semgrep

GitHub

执行 Semgrep 静态代码安全扫描,支持自动语言检测、并行子代理执行及 SARIF 输出。用于代码库安全审计、漏洞发现及已知 bug 模式扫描,强调关闭遥测并需用户确认后方可执行。

skills/semgrep/SKILL.md waybarrios/opencode-power-pack

Trigger Scenarios

请求对代码库进行安全审计 要求进行静态分析扫描以查找漏洞 在代码审查前进行漏洞扫描

Install

npx skills add waybarrios/opencode-power-pack --skill semgrep -g -y
More Options

Use without installing

npx skills use waybarrios/opencode-power-pack@semgrep

指定 Agent (Claude Code)

npx skills add waybarrios/opencode-power-pack --skill semgrep -a claude-code -g -y

安装 repo 全部 skill

npx skills add waybarrios/opencode-power-pack --all -g -y

预览 repo 内 skill

npx skills add waybarrios/opencode-power-pack --list

SKILL.md

Frontmatter
{
    "name": "semgrep",
    "license": "MIT (modified; see UPSTREAMS.json)",
    "description": "Run Semgrep static analysis across a codebase, optionally using Semgrep Pro for cross-file taint analysis. Use when Semgrep or a static-analysis scan is requested; use security-review for a manual audit."
}

Semgrep Security Scan

Run a Semgrep scan with automatic language detection, parallel execution via subagents when the host supports delegation (otherwise scan sequentially), and merged SARIF output.

Essential Principles

  1. Always use --metrics=off — Semgrep sends telemetry by default; --config auto also phones home. Every semgrep command must include --metrics=off to prevent data leakage during security audits.
  2. User must approve the scan plan (Step 3 is a hard gate) — The original "scan this codebase" request is NOT approval. Present exact rulesets, target, engine, and mode; wait for explicit "yes"/"proceed" before spawning scanners.
  3. Third-party rulesets are required, not optional — Trail of Bits, 0xdea, and Decurity rules catch vulnerabilities absent from the official registry. Include them whenever the detected language matches.
  4. Launch all scans concurrently when the host supports subagent delegation — parallel execution per language/category is the core performance advantage. If the host has no subagent/parallel-task mechanism, run the scans sequentially instead of one Task at a time.
  5. Always check for Semgrep Pro before scanning — Pro enables cross-file taint tracking and catches ~250% more true positives. Skipping the check means silently missing critical inter-file vulnerabilities.

When to Use

  • Security audit of a codebase
  • Finding vulnerabilities before code review
  • Scanning for known bug patterns
  • First-pass static analysis

When NOT to Use

  • Binary analysis → Use binary analysis tools
  • Already have Semgrep CI configured → Use existing pipeline
  • Need cross-file analysis but no Pro license → Consider CodeQL as alternative
  • Creating custom Semgrep rules → Use semgrep-rule-creator skill
  • Porting existing rules to other languages → Use semgrep-rule-variant-creator skill

Output Directory

All scan results, SARIF files, and temporary data are stored in a single output directory.

  • If the user specifies an output directory in their prompt, use it as OUTPUT_DIR.
  • If not specified, default to ./static_analysis_semgrep_1. If that already exists, increment to _2, _3, etc.

In both cases, always create the directory with mkdir -p before writing any files.

# Resolve output directory
if [ -n "$USER_SPECIFIED_DIR" ]; then
  OUTPUT_DIR="$USER_SPECIFIED_DIR"
else
  BASE="static_analysis_semgrep"
  N=1
  while [ -e "${BASE}_${N}" ]; do
    N=$((N + 1))
  done
  OUTPUT_DIR="${BASE}_${N}"
fi
mkdir -p "$OUTPUT_DIR/raw" "$OUTPUT_DIR/results"

The output directory is resolved once at the start of Step 1 and used throughout all subsequent steps.

$OUTPUT_DIR/
├── rulesets.txt                 # Approved rulesets (logged after Step 3)
├── raw/                         # Per-scan raw output (unfiltered)
│   ├── python-python.json
│   ├── python-python.sarif
│   ├── python-django.json
│   ├── python-django.sarif
│   └── ...
└── results/                     # Final merged output
    └── results.sarif

Prerequisites

Required: Semgrep CLI (semgrep --version). If not installed, see Semgrep installation docs.

Optional: Semgrep Pro — enables cross-file taint tracking, inter-procedural analysis, and additional languages (Apex, C#, Elixir). Check with:

semgrep --pro --validate --config p/default 2>/dev/null && echo "Pro available" || echo "OSS only"

Limitations: OSS mode cannot track data flow across files. Pro mode uses -j 1 for cross-file analysis (slower per ruleset, but parallel rulesets compensate).

Scan Modes

Select mode in Step 2 of the workflow. Mode affects both scanner flags and post-processing.

Mode Coverage Findings Reported
Run all All rulesets, all severity levels Everything
Important only All rulesets, pre- and post-filtered Security vulns only, medium-high confidence/impact

Important only applies two filter layers:

  1. Pre-filter: --severity MEDIUM --severity HIGH --severity CRITICAL (CLI flag)
  2. Post-filter: JSON metadata — keeps only category=security, confidence∈{MEDIUM,HIGH}, impact∈{MEDIUM,HIGH}

See scan-modes.md for metadata criteria and jq filter commands.

Orchestration Architecture

┌──────────────────────────────────────────────────────────────────┐
│ MAIN AGENT (this skill)                                          │
│ Step 1: Detect languages + check Pro availability                │
│ Step 2: Select scan mode + rulesets (ref: rulesets.md)           │
│ Step 3: Present plan + rulesets, get approval [⛔ HARD GATE]     │
│ Step 4: Run one scan per language/category (parallel if the      │
│         host supports subagent delegation, else sequential)      │
│ Step 5: Merge results and report                                 │
└──────────────────────────────────────────────────────────────────┘
         │ Step 4
         ▼
┌─────────────────┐
│ Per-language    │
│ scan            │
├─────────────────┤
│ Python scanner  │
│ JS/TS scanner   │
│ Go scanner      │
│ Docker scanner  │
└─────────────────┘

Workflow

Follow the detailed workflow in scan-workflow.md. Summary:

Step Action Gate Key Reference
1 Resolve output dir, detect languages + Pro availability Use Glob, not Bash
2 Select scan mode + rulesets rulesets.md
3 Present plan, get explicit approval ⛔ HARD Ask the user directly, or via the host's structured question tool if it has one
4 Run one scan per language/category scanner-task-prompt.md — a prompt template for hosts that delegate to subagents; run the same steps directly otherwise
5 Merge results and report Merge script (below)

Enforcement: Track the 5 steps as a dependency chain (each blocks the next), using the host's task-tracking tool if one is available. Step 3 is a HARD GATE — do not proceed to Step 4 until the user has explicitly approved the plan.

Merge command (Step 5):

uv run scripts/merge_sarif.py $OUTPUT_DIR/raw $OUTPUT_DIR/results/results.sarif

Rationalizations to Reject

Shortcut Why It's Wrong
"User asked for scan, that's approval" Original request ≠ plan approval. Present plan, use AskUserQuestion, await explicit "yes"
"Step 3 task is blocking, just mark complete" Lying about task status defeats enforcement. Only mark complete after real approval
"I already know what they want" Assumptions cause scanning wrong directories/rulesets. Present plan for verification
"Just use default rulesets" User must see and approve exact rulesets before scan
"Add extra rulesets without asking" Modifying approved list without consent breaks trust
"Third-party rulesets are optional" Trail of Bits, 0xdea, Decurity catch vulnerabilities not in official registry — REQUIRED
"Use --config auto" Sends metrics; less control over rulesets
"One scan at a time when parallel is possible" Defeats the performance advantage; run all per-language scans concurrently when the host supports it
"Pro is too slow, skip --pro" Cross-file analysis catches 250% more true positives; worth the time
"Semgrep handles GitHub URLs natively" URL handling fails on repos with non-standard YAML; always clone first
"Cleanup is optional" Cloned repos pollute the user's workspace and accumulate across runs
"Use . or relative path as target" Parallel/delegated scans need absolute paths to avoid ambiguity
"Let the user pick an output dir later" Output directory must be resolved at Step 1, before any files are created

Reference Index

File Content
rulesets.md Complete ruleset catalog and selection algorithm
scan-modes.md Pre/post-filter criteria and jq commands
scanner-task-prompt.md Prompt template for delegating a per-language scan to a subagent
Workflow Purpose
scan-workflow.md Complete 5-step scan execution process

Success Criteria

  • Output directory resolved (user-specified or auto-incremented default)
  • All generated files stored inside $OUTPUT_DIR
  • Languages detected with file counts; Pro status checked
  • Scan mode selected by user (run all / important only)
  • Rulesets include third-party rules for all detected languages
  • User explicitly approved the scan plan (Step 3 gate passed)
  • All per-language scans launched concurrently (or sequentially if the host has no delegation) and completed
  • Every semgrep command used --metrics=off
  • Approved rulesets logged to $OUTPUT_DIR/rulesets.txt
  • Raw per-scan outputs stored in $OUTPUT_DIR/raw/
  • results.sarif exists in $OUTPUT_DIR/results/ and is valid JSON
  • Important-only mode: post-filter applied before merge; unfiltered results preserved in raw/
  • Results summary reported with severity and category breakdown
  • Cloned repos (if any) cleaned up from $OUTPUT_DIR/repos/

Version History

  • f198a18 Current 2026-08-16 09:13

Same Skill Collection

skills/agentic-actions-auditor/SKILL.md
skills/agents-md-revise/SKILL.md
skills/ai-slop/SKILL.md
skills/code-architect/SKILL.md
skills/code-explorer/SKILL.md
skills/code-quality/SKILL.md
skills/code-review/SKILL.md
skills/code-reviewer/SKILL.md
skills/codeql/SKILL.md
skills/design-patterns/SKILL.md
skills/differential-review/SKILL.md
skills/feature-dev/SKILL.md
skills/fp-check/SKILL.md
skills/frontend-design/SKILL.md
skills/hf-cli/SKILL.md
skills/hf-cloud-aws-context-discovery/SKILL.md
skills/hf-cloud-python-env-setup/SKILL.md
skills/hf-cloud-sagemaker-deployment-planner/SKILL.md
skills/hf-cloud-sagemaker-iam-preflight/SKILL.md
skills/hf-cloud-sagemaker-production-defaults/SKILL.md
skills/hf-cloud-serving-image-selection/SKILL.md
skills/hf-mem/SKILL.md
skills/huggingface-best/SKILL.md
skills/huggingface-community-evals/SKILL.md
skills/huggingface-datasets/SKILL.md
skills/huggingface-gradio/SKILL.md
skills/huggingface-llm-trainer/SKILL.md
skills/huggingface-local-models/SKILL.md
skills/huggingface-lora-space-builder/SKILL.md
skills/huggingface-paper-publisher/SKILL.md
skills/huggingface-papers/SKILL.md
skills/huggingface-spaces/SKILL.md
skills/huggingface-tool-builder/SKILL.md
skills/huggingface-trackio/SKILL.md
skills/huggingface-vision-trainer/SKILL.md
skills/huggingface-zerogpu/SKILL.md
skills/insecure-defaults/SKILL.md
skills/mcp-builder/SKILL.md
skills/paper-summarizer/SKILL.md
skills/sarif-parsing/SKILL.md
skills/security-review/SKILL.md
skills/security-threat-model/SKILL.md
skills/semgrep-rule-creator/SKILL.md
skills/semgrep-rule-variant-creator/SKILL.md
skills/sharp-edges/SKILL.md
skills/skill-creator/SKILL.md
skills/supply-chain-risk-auditor/SKILL.md
skills/train-sentence-transformers/SKILL.md
skills/transformers-js/SKILL.md

Metadata

Files
0
Version
f198a18
Hash
adc681b6
Indexed
2026-08-16 09:13

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-16 21:21
浙ICP备14020137号-1 $mapa de visitantes$