Overview
Semgrep scans source code for patterns that may indicate security bugs, unsafe APIs and policy violations. It supports developer workflows and CI checks, but findings must be reviewed in context to distinguish exploitable issues from false positives.
Key features
Static analysis; customizable rules; multi-language support; CI integration; community rule collections.
Install & first run
# Python package
python3 -m pip install --user semgrep
# or
brew install semgrep
# Docker
docker run --rm -v "${PWD}:/src" semgrep/semgrep semgrep scan --config auto
# Scan the current repository with the community rules
semgrep --config auto .
# Use a published ruleset and fail CI on findings
semgrep --config p/owasp-top-ten --error ./src
--config auto picks rules from the languages it detects; pin a ruleset instead for reproducible CI runs. Docs: https://semgrep.dev/docs/
Real-world example
Scan a repository you maintain before merging a change, then fix confirmed high-impact issues and add regression tests.
Common questions
Can static analysis prove exploitability?
No. Use the finding as a lead and validate data flow, reachability and impact.
Is it just regex?
No - it parses the code into an AST, so a rule matches structure and data flow, not text. That is why it survives reformatting and catches tainted input.
How fast is it?
Seconds on a mid-sized repo for a small rule set, which is why it works as a pre-commit or PR gate rather than a nightly job.
Which rules do I start with?
--config auto picks community rules from the detected languages. Pin a ruleset (p/owasp-top-ten, p/secrets) for reproducible CI results.
Related tools
Gitleaks
Scan git history or a plain directory for committed API keys, tokens and passwords, then block new ones before the commit. Free, open source.
TruffleHog
Scan git history, filesystems and container images for secrets, then verify which keys are actually live. Free, open source.
Keep exploring: browse every assessment phase in the Pentest Hub.
Authorized testing only — only ever test systems you own or have explicit written permission to assess.
