CLI 目录 横向对比 FCRS-1.0 标准 /llms.txt
← 返回 CLI 目录

CodeQL CLI

$ codeql 官方出品 低风险
GitHub · 文件检索与编辑 · GitHub CodeQL Terms (Free for OSS) · macos / linux / windows

GitHub 官方 CodeQL CLI 可将代码库构建为关系型 AST/数据流数据库(database create),并执行 QL 安全或结构化查询(database analyze、query run)。结果支持导出为 SARIF JSON(--format=sarif-latest)或解码为 JSON(bqrs decode --format=json)。

FCRS-1.0 综合评分
86 /100
良好 (Good)
中置信度 (源码/文档)
零摩擦安装命令
brew install codeql
CLI vs MCP 选型建议 优先选 CLI

本地 codeql database create 与 analyze --format=sarif-latest 直接针对本地构建执行耗时的深度静态分析。

Agent 友好度体检单

✓ 原生 JSON 输出
— 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
— 只读模式开关
— 支持 NO_COLOR
✓ 自省/Schema 发现
— 官方 SKILL.md

当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。

FCRS-1.0 六维评分拆解

Agent 友好度 21 / 25

支持无头导出结构化 SARIF JSON(--format=sarif-latest)与 bqrs decode --format=json,但多步建库与查询流程较重。

  • Supports --format=sarif-latest, bqrs decode --format=json, --threads, and --ram
  • Requires building a database before querying
安全与权限边界 21 / 25

本地分析不改动源码(database create 仅写入独立数据库目录);github upload-results 需显式调用并提供 GITHUB_TOKEN。

  • Source tree remains untouched during DB creation and analysis
  • --overwrite deletes and replaces an existing DB directory
安装与运行摩擦 11 / 15

可通过 brew install codeql 或 GitHub Releases 安装,内置 JVM 体积较大,且编译型语言需复现完整构建命令。

  • Heavy binary distribution + build-tracer requirement for compiled languages
能力覆盖与边际价值 14 / 15

具备跨过程污点追踪与语义数据流分析能力,远超正则或单文件 AST 工具。

  • Whole-program call-graph and dataflow queries
维护与来源背书 10 / 10

GitHub 官方安全分析引擎,迭代频繁并提供官方维护的标准查询包。

  • Official GitHub product (github/codeql)
文档与可验证性 9 / 10

GitHub Docs 提供详尽的 CLI 参考、QL 语言指南与 --help 命令树。

  • Comprehensive official CodeQL CLI reference

安全边界、鉴权与放权指南

鉴权方式
无需鉴权 环境变量密钥
凭证存储位置

本地分析无需凭据;执行 codeql github upload-results 时使用 GITHUB_TOKEN 或 --github-auth-stdin。

潜在副作用
只读查询 本地写入 远端写入
费用与配额提示

对 OSI 开源仓库与学术研究免费;私有商业仓库的自动化扫描需购买 GitHub Advanced Security 许可。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# CodeQL CLI Agent Rules
- Always export analysis with `--format=sarif-latest` or `bqrs decode --format=json` instead of parsing terminal tables.
- Check CodeQL licensing before running automated CI scans on private commercial repositories; avoid `--overwrite` unless rebuilding a stale DB.

Agent 高频安全命令配方

只读查询(安全推荐)

分析 CodeQL 数据库并导出 SARIF JSON
codeql database analyze ./codeql-db --format=sarif-latest --output=results.sarif codeql/javascript-queries

针对 ./codeql-db 运行标准 CodeQL 查询包并输出 JSON 结构的 SARIF 结果。

将 BQRS 查询结果解码为 JSON
codeql bqrs decode --format=json --output=results.json -- results.bqrs

将 codeql query run 生成的二进制 .bqrs 文件转换为结构化 JSON。

受控写入与预演

为 Python 项目构建本地 CodeQL 数据库
codeql database create ./codeql-db --language=python --source-root=.

在 ./codeql-db 中创建本地关系型 AST/数据流数据库,不修改源代码文件。

核心优势

  • + 支持全程序跨过程 AST 与污点流分析,并导出标准 SARIF JSON。
  • + bqrs decode --format=json 可将自定义 QL 查询结果转为整洁 JSON。

注意事项与踩坑点

  • ! 针对闭源商业仓库的自动化扫描需要 GitHub Advanced Security 商业许可。
  • ! 编译型语言的数据库构建耗时较长,且需提供可用的构建命令(--command)。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI