sast-semgrep

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SAST Scan with Semgrep

使用Semgrep进行SAST扫描

You are a security engineer running static application security testing (SAST) using Semgrep.
你是一名安全工程师,正在使用Semgrep进行静态应用安全测试(SAST)。

When to use

适用场景

Use this skill when asked to perform a SAST scan, static analysis, or security code review on any codebase. Semgrep supports Python, JavaScript/TypeScript, Java, Go, C/C++, Ruby, PHP, C#, Kotlin, Swift, Rust, and more.
当需要对任何代码库执行SAST扫描、静态分析或安全代码审查时,可使用本技能。Semgrep支持Python、JavaScript/TypeScript、Java、Go、C/C++、Ruby、PHP、C#、Kotlin、Swift、Rust等多种语言。

Prerequisites

前置条件

  • Semgrep CLI installed (
    pip install semgrep
    or
    brew install semgrep
    )
  • Verify:
    semgrep --version
  • 已安装Semgrep CLI(
    pip install semgrep
    brew install semgrep
  • 验证安装:
    semgrep --version

Instructions

操作步骤

  1. Identify the target — Determine the file(s) or directory to scan from the user's request.
  2. Select the ruleset — Choose the appropriate config:
    • General security:
      --config=auto
      (recommended default)
    • OWASP Top 10:
      --config=p/owasp-top-ten
    • Language-specific:
      --config=p/python
      ,
      --config=p/javascript
      ,
      --config=p/java
      , etc.
    • CI-focused:
      --config=p/ci
    • Secrets:
      --config=p/secrets
  3. Run the scan:
    bash
    semgrep scan --config=auto --json --output=semgrep-results.json <target-path>
  4. Parse the results — Read the JSON output and present findings in this format:
| # | Severity | Rule ID | File:Line | Finding | Remediation |
|---|----------|---------|-----------|---------|-------------|
  1. Summarize — Provide:
    • Total files scanned and findings count by severity (ERROR / WARNING / INFO)
    • Critical findings first with code context
    • Specific remediation steps referencing Semgrep rule documentation
  1. 确定目标 — 根据用户的需求,确定要扫描的文件或目录。
  2. 选择规则集 — 选择合适的配置:
    • 通用安全扫描:
      --config=auto
      (推荐默认选项)
    • OWASP Top 10:
      --config=p/owasp-top-ten
    • 特定语言:
      --config=p/python
      --config=p/javascript
      --config=p/java
    • CI场景:
      --config=p/ci
    • 敏感信息检测:
      --config=p/secrets
  3. 运行扫描
    bash
    semgrep scan --config=auto --json --output=semgrep-results.json <target-path>
  4. 解析结果 — 读取JSON输出,并按以下格式呈现发现的问题:
| 序号 | 严重程度 | 规则ID | 文件:行号 | 问题描述 | 修复建议 |
|---|----------|---------|-----------|---------|-------------|
  1. 总结报告 — 提供以下内容:
    • 扫描的文件总数,以及按严重程度(ERROR / WARNING / INFO)统计的问题数量
    • 优先展示高危问题及代码上下文
    • 参考Semgrep规则文档提供具体的修复步骤

Common Rulesets

常用规则集

RulesetConfig FlagUse Case
Auto (recommended)
--config=auto
Best overall coverage
OWASP Top 10
--config=p/owasp-top-ten
Compliance-focused
Secrets
--config=p/secrets
Detect hardcoded secrets
Default
--config=p/default
Curated high-signal rules
CI
--config=p/ci
Fast, low false-positive
规则集配置标识适用场景
Auto(推荐)
--config=auto
最佳全面覆盖
OWASP Top 10
--config=p/owasp-top-ten
合规性检测
敏感信息
--config=p/secrets
检测硬编码敏感信息
默认规则
--config=p/default
精选高可信度规则
CI场景
--config=p/ci
快速扫描,低误报