How to Run Your First Semgrep Security Scan

October 28, 2026

Semgrep is a static analysis tool that scans source code for security bugs and code patterns. It’s free and open source (semgrep CLI), runs in seconds on most repos, and its rules are written in the language they analyse — so a Python rule looks like Python.

The good news is the install takes two minutes. The harder part is that a first run on a real codebase gives you 500 findings and 470 of them are noise. Below is how to get to the useful 30.

How do you install and run Semgrep?

On macOS or Linux, Homebrew or pipx. Avoid plain pip install into your system Python — Semgrep pulls in tree-sitter binaries and version conflicts are annoying.

brew install semgrep
OR:
pipx install semgrep
semgrep --version

Then, in your repo root:

semgrep --config auto

--config auto sends a hash of your repo’s languages to Semgrep’s servers and downloads the relevant community rules. If you’d rather not phone home, use a named registry ruleset:

semgrep --config p/default    # broad security + best practice
semgrep --config p/security-audit

Or a local rule file — the offline path:

semgrep --config ./semgrep.yml src/

A minimal rule looks like this:

rules:
  - id: python-eval-user-input
    languages: [python]
    severity: ERROR
    message: Never pass request data to eval()
    patterns:
      - pattern: eval(...)
      - pattern-inside: |
          def $FUNC(...):
            ...

pattern matches code shape, not text. eval(...) matches any call to eval with any arguments, and pattern-inside scopes it to functions. That composition is why Semgrep rules are readable — you describe the violation instead of writing a regex that guesses at it.

What do the findings actually mean?

The output is one line per finding with a rule id, file, line and severity. Three severities: ERROR (real vulnerability), WARNING (suspicious), INFO (style).

Rule ids are namespaced by source — python.lang.security.audit.eval-detected tells you it’s from the Python language ruleset, security category, audit tier.

On a first run, sort by rule id rather than by file. The same rule firing 200 times is one decision, not 200. Common high-volume offenders:

  • python.lang.security.audit.eval-detected — usually test code or admin scripts.
  • javascript.express.security.audit.express-check-csurf — fires on any state-changing handler without CSRF middleware.
  • generic.secrets.security.detected-private-key — does what it says; take these seriously.
  • Hardcoded-password rules — noisy in fixtures, critical in src/.

The --json output with jq gets you the grouping in one line:

semgrep --config auto --json | jq -r '.results[].check_id' | sort | uniq -c | sort -rn

Five rules will typically account for 80% of findings. Decide on those five and you’ve triaged the scan.

How do you cut false positives without suppressing real bugs?

Three mechanisms, in increasing order of severity:

nosemgrep: rule-id comment on the offending line. Use for confirmed false positives only — a regex in a test fixture that looks like a secret, for example. Always include the rule id; a bare nosemgrep with no rule id suppresses everything on that line and hides future bugs.

.semgrepignore works like .gitignore. Add vendored directories, generated code, and node_modules. This is the one people need first — scanning a checked-in dist/ folder produces thousands of irrelevant findings.

Severity filtering in config: --severity ERROR shows only errors. Good for a CI gate, bad for an audit, because it hides the warnings that indicate risk.

The unhelpful move is --exclude=src/. If a rule is too noisy to keep, exclude the rule (--config a curated file) rather than the code, so the exclusion is visible and reviewable.

How do you add Semgrep to CI?

Start in advisory mode. A PR gate that fails on day one gets reverted.

- name: Semgrep
  run: semgrep --config auto --error --severity ERROR

--error makes Semgrep exit non-zero when it finds an ERROR-severity match. Without it, the step always passes and nobody looks at the log.

Run it on changed files only for speed, but keep a nightly full scan — incremental PR scans never see the bugs you inherited.

semgrep --config auto --error --severity ERROR $(git diff --name-only origin/main...HEAD | grep -E '\.(py|js|ts|go|rb)$')

The realistic path: run advisory for two weeks, count how many ERROR findings turn out to be real, then gate on the rules where you had a real hit and a fix. That’s usually three to five rules, not the whole registry.

Is Semgrep AppSec Platform worth paying for?

The paid platform adds a managed dashboard, PR comments with autofix suggestions, dependency scanning and the “Pro” rules (which catch higher-confidence, higher-complexity issues). Pricing is per contributor and starts in the low tens of dollars per month per developer, quoted annually.

For one developer, no. The CLI covers code scanning and you can wire PR comments with a GitHub Action in 20 minutes.

For a team of ten where nobody owns security, the dashboard’s value is that findings stop disappearing. The number one failure mode of free Semgrep adoption is that the first scan’s 500 findings are ignored and the tool gets removed. Paying for a dashboard doesn’t fix that — assigning one person to triage does.

What Semgrep won’t find

Logic flaws. If a user can pass someone else’s account_id to an endpoint, Semgrep has no idea the account shouldn’t belong to them. That requires reading the code or dynamic testing.

Multi-file data flows beyond first-order taint. Semgrep does track taint mode (mode: taint with sources and sinks), and it works well within a function or module. Across a queue or a service boundary, it doesn’t see.

Quick Summary

  • Install with brew install semgrep or pipx install semgrep; run semgrep --config auto.
  • Add .semgrepignore before the first scan or vendored code will drown the results.
  • Group findings by rule id — five rules usually account for 80% of output.
  • Use nosemgrep: rule-id comment for confirmed false positives, never a bare nosemgrep with no rule id.
  • Gate CI only on rules that have caught something real; run advisory for two weeks first.
  • Semgrep cannot detect authorisation logic bugs — that still needs human review.
Tags: