Semgrep
$ semgrep 官方出品 低风险semgrep 在 30 余种编程语言上执行语法感知的安全与缺陷规则分析。Agent 可使用 semgrep scan --json --metrics=off --quiet 运行本地 YAML 或开源规则包,并通过 --dryrun 安全预览自动修复。
brew install semgrep 在仓库内直接运行 semgrep scan --json 即可本地获取完整 SAST 检测结果,无需 MCP 包装。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
支持 --json、--sarif、--quiet、--metrics=off、--dryrun 与 --error 退出码控制。
- Native
--json,--dryrun, and--metrics=offflags
默认只读,仅在显式开启 --autofix(且未带 --dryrun)时修改文件;--metrics=off 可关闭遥测。
- Telemetry opt-out via
--metrics=off; read-only default scan
macOS 与 Linux 可通过 brew 或 pip install semgrep 轻松安装(Windows 需借助 WSL2)。
- macOS and Linux native support; no native Windows binary
用易读的 YAML 规则兼顾自定义模式匹配与 SAST 污点分析。
- 30+ languages with YAML rule authoring and
--autofix
由 Semgrep Inc. 持续主力研发(semgrep/semgrep),AppSec 社区认可度高。
- Active vendor-backed repository
semgrep.dev/docs/ 对 CLI 参数、规则语法与 JSON 结构说明详尽。
- Comprehensive official documentation
安全边界、鉴权与放权指南
连接 Semgrep Cloud 时可选配置 SEMGREP_APP_TOKEN 或 ~/.semgrep/settings.yml;本地/开源规则包无需登录。
开源引擎免费(LGPL-2.1);Semgrep Pro 跨文件分析规则需商业授权。
# Semgrep Agent Rules - Always pass `--json --metrics=off --quiet` for structured findings without telemetry or spinner noise. - Preview `--autofix` with `--dryrun` first; use local rule files (`--config ./rules.yaml`) in air-gapped environments.
Agent 高频安全命令配方
只读查询(安全推荐)
semgrep scan --config p/default --json --metrics=off --quiet .
扫描常见安全漏洞并输出干净的结构化 JSON 报告。
semgrep scan --config ./rules.yaml --autofix --dryrun --json .
在 JSON 中预览拟议的 fix 替换内容而不修改任何源文件。
受控写入与预演
semgrep scan --config ./rules.yaml --autofix --metrics=off .
经过干跑核验后,将自动化规则修复原地写入代码。
核心优势
- + 跨 30+ 语言输出高信息密度
--jsonSAST 结果,并支持--metrics=off关闭遥测。 - + 修改代码前可通过
--autofix --dryrun安全预览修复补丁。
注意事项与踩坑点
- ! 使用
--config auto或p/...规则包会联网拉取规则,离线需改用本地 YAML 并附带--metrics=off。 - ! 不支持原生 Windows,需在 WSL 环境下运行。