| name | security-scan |
| description | Run real SAST and secret-scanning tools locally (semgrep, bandit, gitleaks, trivy). Use when auditing a codebase for vulnerabilities, exposed secrets, or vulnerable dependencies before shipping or on demand. |
| requires_bins | [] |
When to use
- Pre-merge security gate on a feature branch
- Auditing a new dependency or third-party codebase
- Checking for secrets accidentally committed
- Scanning container images or IaC for CVEs
Tools at a glance
| Tool | Best for | Language |
|---|
| semgrep | SAST patterns, custom rules | Any (Python, JS, Go, Java, …) |
| bandit | Python-specific SAST | Python only |
| gitleaks | Secret/credential scanning | Any (git history + working tree) |
| trivy | Dep CVEs, IaC misconfig, container images | Any |
semgrep — Multi-language SAST
Install
pip install semgrep
brew install semgrep
Run
semgrep --config auto .
semgrep --config "p/owasp-top-ten" .
semgrep --config "p/secrets" .
semgrep --config "p/python" .
semgrep --config auto src/
semgrep --config auto --json . > semgrep_results.json
Interpret findings
severity: ERROR → P0 — likely exploitable; fix before merge
severity: WARNING → P1 — review carefully; context-dependent
severity: INFO → P2 — style/hygiene; triage manually
Ignore a false positive (inline)
return query + user_input
bandit — Python SAST
Install
pip install bandit
Run
bandit -r src/
bandit -r src/ -l -i
bandit -r src/ -f json -o bandit_report.json
bandit -r src/ --skip B101
Key finding IDs to prioritize
| ID | Issue |
|---|
| B102 | exec / eval with user input |
| B106 | Hardcoded password argument |
| B201 | Flask debug=True |
| B301/B302 | pickle deserialization |
| B501–B509 | Weak SSL/TLS config |
| B601–B608 | Shell injection / SQL injection |
gitleaks — Secret scanning
Install
brew install gitleaks
Run
gitleaks detect --source . --report-format json --report-path gitleaks.json
gitleaks detect --no-git --source . --report-format json --report-path gitleaks.json
gitleaks protect --staged
Baseline an existing repo (suppress old findings)
gitleaks detect --source . --baseline-path gitleaks-baseline.json --report-path gitleaks-baseline.json
gitleaks detect --source . --baseline-path gitleaks-baseline.json
Gotcha: gitleaks scans git-tracked content. Untracked files need --no-git.
Rotate any real credential found — assume it was exfiltrated the moment it hit version control.
trivy — Dependency CVEs + IaC + containers
Install
brew install aquasecurity/trivy/trivy
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
Run
trivy fs .
trivy fs --scanners vuln requirements.txt
trivy fs --severity CRITICAL,HIGH .
trivy image python:3.11-slim
trivy fs --format json --output trivy_report.json .
trivy fs --exit-code 1 --severity CRITICAL .
Reading trivy output
CRITICAL → P0: known exploitable CVE; patch immediately
HIGH → P1: serious; patch before shipping
MEDIUM → P2: assess exploitability in your context
LOW/UNKNOWN → P3: informational; track but don't block
Triage workflow
- Run all four on the target repo/dir.
- Deduplicate: semgrep + bandit often flag the same Python issue; keep one finding.
- Classify each finding:
- Reachable from untrusted input? → P0/P1
- Dependency CVE with available fix? → P1
- Secret in git history? → P0, rotate NOW
- False positive / test code? → suppress with inline comment or
.semgrepignore/.gitleaksignore
- Output a prioritized list (P0 → P1 → P2) with file:line, tool, and remediation note.
- Re-run after fixes to confirm findings resolved.
Suppress false positives
tests/
vendor/
subprocess.call(cmd, shell=True)
echo "abc123fingerprint" >> .gitleaksignore
CVE-2023-12345