Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

semgrep

БесплатноБез исполняемых скриптовНе проверен

Semgrep is an open-source static analysis tool that finds bugs, security vulnerabilities and anti-patterns by matching code patterns. Use it to scan a…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

Semgrep

Overview

Semgrep is an open-source static analysis engine (LGPL-2.1 CLI, repository semgrep/semgrep) that matches code structure instead of text, so a rule reads almost like the source it finds. It supports 30+ languages. The CLI runs locally and offline with your own rules; community rules come from the Semgrep Registry; the paid Semgrep AppSec Platform adds dashboards, triage and diff-aware CI. This skill was checked against Semgrep 1.178 and 1.179 (September 2026).

Instructions

Install

python3 -m pip install semgrep      # needs Python 3.10+
# or: brew install semgrep          # Homebrew no longer supports Intel Macs
# or: docker run --rm -v "$PWD:/src" semgrep/semgrep semgrep scan --config p/security-audit
semgrep --version

Scan

semgrep scan --config p/security-audit src/        # a registry ruleset
semgrep scan --config p/owasp-top-ten --config p/typescript
semgrep scan --config .semgrep/ --metrics=off      # local rules only, fully offline
semgrep scan --config auto .                       # rules picked for the project's languages

--config auto sends the project URL to the Registry and enables metrics; for private code or air-gapped runs use explicit p/... rulesets or local files with --metrics=off. Registry rulesets are listed at semgrep.dev/explore.

Useful flags: --severity=ERROR, --error (exit code 1 when findings exist), --json, --sarif --output=semgrep.sarif, --exclude-rule, --include='*.ts', -a/--autofix (applies each rule's fix), --baseline-commit=origin/main (report only findings new since that commit). Ignore a line with a trailing // nosemgrep: rule-id; a .semgrepignore file excludes paths. Since 1.117 .gitignore is no longer read automatically.

Custom rules

Required keys are id, message, severity, languages and one pattern operator. Severities in rules are ERROR, WARNING, INFO (newer docs also list LOW to CRITICAL). Operator logic: pattern-either is OR, patterns is AND, and pattern-not and metavariable-regex only work inside patterns. A string such as "sk_live_..." is not a prefix match ("..." matches any string); use metavariable-regex for that.

# .semgrep/node-security.yml
rules:
  - id: sql-query-built-from-input
    message: SQL built from user input. Use a parameterized query, for example db.query("SELECT * FROM users WHERE id = $1", [userId]).
    severity: ERROR
    languages: [typescript, javascript]
    pattern-either:
      - pattern: $DB.query(`...${$INPUT}...`)
      - pattern: $DB.query("..." + $INPUT)
    metadata:
      cwe: ["CWE-89: SQL Injection"]
      confidence: HIGH

  - id: hardcoded-stripe-key
    message: Hardcoded Stripe key. Read it from process.env.STRIPE_SECRET_KEY.
    severity: ERROR
    languages: [typescript, javascript]
    patterns:
      - pattern-either:
          - pattern: $KEY = "$VALUE"
          - pattern: const $KEY = "$VALUE"
      - metavariable-regex:
          metavariable: $VALUE
          regex: ^sk_(live|test)_

  - id: route-without-auth
    message: Route handler without authMiddleware.
    severity: WARNING
    languages: [typescript, javascript]
    patterns:
      - pattern: router.$METHOD($PATH, async (req, res) => { ... })
      - pattern-not: router.$METHOD($PATH, authMiddleware, async (req, res) => { ... })

  - id: unsanitized-inner-html
    message: dangerouslySetInnerHTML with unsanitized input risks XSS.
    severity: ERROR
    languages: [typescript, javascript]
    pattern: |
      <$TAG dangerouslySetInnerHTML={{__html: $INPUT}} />
    fix: |
      <$TAG dangerouslySetInnerHTML={{__html: DOMPurify.sanitize($INPUT)}} />

Quote or use | for any message or pattern that contains : , otherwise YAML fails with "mapping values are not allowed here". Check a rule file with semgrep --validate --config .semgrep/, and unit-test rules by putting // ruleid: rule-id above lines that must match and // ok: rule-id above lines that must not in a file next to the rule, then run semgrep --test .semgrep/.

CI (GitHub Actions)

The semgrep/semgrep-action is the old way; the documented setup runs semgrep ci in the official container. semgrep ci needs SEMGREP_APP_TOKEN (a platform account) and scans only changed files on pull requests.

# .github/workflows/semgrep.yml
name: Semgrep
on:
  pull_request: {}
  push:
    branches: [main]
jobs:
  semgrep:
    runs-on: ubuntu-latest
    container:
      image: semgrep/semgrep
    steps:
      - uses: actions/checkout@v4
      - run: semgrep ci
        env:
          SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}

Without an account, run the open-source CLI directly and upload SARIF:

      - run: pip install semgrep
      - run: semgrep scan --config p/security-audit --config .semgrep/ --metrics=off --sarif --output=semgrep.sarif --error --baseline-commit=origin/${{ github.base_ref }}

Use fetch-depth: 0 on check

Полный SKILL.md на GitHub

Установить semgrep в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл semgrep?

Semgrep is an open-source static analysis tool that finds bugs, security vulnerabilities and anti-patterns by matching code patterns. Use it to scan a repository, write custom YAML rules, auto-fix findings, or add a Semgrep scan with SARIF output to GitHub Actions or other CI.

Как установить скилл semgrep?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл semgrep запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить semgrep с