SAST and SCA in CI Pipelines
Automate static code analysis and dependency scanning in pull requests, then tune them so developers trust the results.
Intermediate · about 6 hours · difficulty 3/5
Learn first: Secure Coding and Input Validation, Dependency and Supply-Chain Hygiene
Automated checks catch common mistakes on every change, before they reach production. The two most widely used are SAST and SCA.
SAST: static application security testing
Analyses your source code without running it, looking for patterns such as untrusted input reaching a database query or a weak crypto call.
- Free options: Semgrep (community rules), CodeQL (free for public repos on GitHub), language linters like Bandit for Python and ESLint security plugins.
- Strength: finds issues in your own code early. Weakness: false positives and limited understanding of business logic.
SCA: software composition analysis
Checks your dependencies against known vulnerabilities and licences.
- Tools: OSV-Scanner, Trivy, Dependabot alerts,
npm audit,pip-audit. - Trivy also scans container images and infrastructure-as-code for misconfigurations.
Designing the pipeline
- Run fast scans on every pull request and fuller scans nightly.
- Show results inline in the PR so developers see them in context.
- Start in report-only mode, tune rules, then block only on high-confidence, high-severity findings.
- Track suppressions with a reason, reviewer and expiry.
Measuring success
Watch fix rates and time to fix, not just finding counts. A tool nobody trusts will be ignored or disabled.
Pitfalls
- Enabling every rule and flooding teams with noise.
- Scanning only the default branch, after the risky code is already merged.
Move on when you have a CI workflow that runs Semgrep or CodeQL plus an SCA scanner on pull requests, with at least one tuned rule and a documented suppression.
Key concepts
- SAST concepts and limits
- Semgrep rules
- CodeQL
- SCA and dependency scanning
- Trivy for images and IaC
- PR-inline results and gating
- Tuning and suppressions
- DAST overview: Scanning your own running app in a test environment
Mini project
Create a GitHub Actions workflow that runs Semgrep and OSV-Scanner on pull requests, reports results inline, and fails the build only on high-severity findings; document your tuning decisions in the README.
Check yourself
Why should a new security scanner usually start in report-only mode before it blocks merges?
Free resources
- Semgrep documentation (Semgrep)
- CodeQL documentation (GitHub)
- OSV-Scanner (Google / OSV)
- Trivy documentation (Aqua Security)