How do we add SAST, dependency and container scanning to our CI pipeline without slowing releases?
17 Nov 2026 · 7 min read

Short answer: Run the three scans as parallel jobs on every pull request, scan only what the pull request changed, and block the merge only on new, fixable high or critical findings. Report everything else without blocking. Run full scans of the whole codebase and every image nightly instead of on every commit.
Start in warn-only mode for two to four weeks, then turn on the gate once the backlog is triaged. Done this way, the scans run alongside your tests instead of after them, and they never hold up a release over an old finding nobody can fix today.
The three scans, and what each one catches
| Scan | What it looks at | Catches | Open-source tools we use | Good alternatives |
|---|---|---|---|---|
| SAST (static analysis) | Your own source code | Injection, broken authorisation checks, unsafe deserialisation, hard-coded secrets in code | Semgrep | CodeQL, SonarQube |
| Dependency scanning (SCA) | Lockfiles: package-lock.json, poetry.lock, go.sum, pom.xml … | Known CVEs in third-party libraries | Trivy (trivy fs) | OSV-Scanner, Dependabot alerts, Grype |
| Container scanning | The built image: OS packages plus app dependencies | CVEs in the base image and system libraries, misconfigured Dockerfiles | Trivy (trivy image) | Grype, Docker Scout |
Add secrets scanning (gitleaks or TruffleHog) next to these. It's the cheapest of the four and catches the incident you least want.
Step by step
- Put each scan in its own job, in parallel with your tests. None of these scans depends on the test run, so on a typical pipeline they finish inside the time the test suite already takes. Container scanning has to wait for the image build, but it can run alongside integration tests.
- Scan the diff on pull requests, everything at night. Semgrep can report only findings introduced since the base branch (
semgrep scan --baseline-commit <base-sha>, orsemgrep ci, which does this automatically on pull requests when connected to the Semgrep platform). Keep a nightly scheduled workflow that scans the whole repository and every deployed image, so old findings are still tracked. - Cache the vulnerability database. Trivy downloads its vulnerability database on each run unless it's cached. Cache the Trivy cache directory between runs (the
aquasecurity/trivy-actionhas a cache option). This is often the single biggest time saving. - Gate only on what a developer can act on today. Fail the job only for high or critical findings that already have a fix:
trivy image --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 <image>. Report everything else as an annotation or a comment. - Put findings where the developer already is. Upload results as SARIF so they appear as inline annotations on the pull request (GitHub code scanning reads SARIF from Semgrep and Trivy). A finding in a PDF report gets ignored; a comment on the changed line gets fixed.
- Start warn-only, then switch on the gate. Run every scan with
--exit-code 0for two to four weeks. Triage the backlog: fix, accept with a dated exception (.trivyignoreandnosemgrepwith a reason and an owner), or mark as false positive. Only then make the scan a required status check. - Keep exceptions honest. Every ignored finding gets a reason, an owner and an expiry date, reviewed monthly. An ignore list without expiry dates turns into a list of vulnerabilities everyone has agreed to forget.
- Protect the pipeline itself. Pin third-party actions to a full commit SHA rather than a tag (the March 2025
tj-actions/changed-filescompromise rewrote tags to steal CI secrets), give jobs the leastpermissions:they need, and never expose deployment credentials to workflows triggered by forks.
Example: GitHub Actions
# .github/workflows/security.yml (simplified; pin actions to commit SHAs in real use)
on:
pull_request:
schedule: [{ cron: "0 2 * * *" }] # nightly full scan
permissions:
contents: read
security-events: write # SARIF upload
jobs:
sast:
runs-on: ubuntu-latest
container: semgrep/semgrep
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- run: semgrep scan --config p/default --sarif --output semgrep.sarif --baseline-commit "${{ github.event.pull_request.base.sha }}"
if: github.event_name == 'pull_request'
- run: semgrep scan --config p/default --sarif --output semgrep.sarif
if: github.event_name == 'schedule'
- uses: github/codeql-action/upload-sarif@v3
with: { sarif_file: semgrep.sarif }
dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: aquasecurity/trivy-action@<pinned-sha>
with:
scan-type: fs
severity: HIGH,CRITICAL
ignore-unfixed: true
exit-code: "1"
cache: true
image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: docker build -t app:${{ github.sha }} .
- uses: aquasecurity/trivy-action@<pinned-sha>
with:
image-ref: app:${{ github.sha }}
severity: HIGH,CRITICAL
ignore-unfixed: true
exit-code: "1"
cache: trueWhat usually slows teams down (and the fix)
| Symptom | Cause | Fix |
|---|---|---|
| Every PR fails on day one | Gate switched on before the backlog was triaged | Warn-only first, then gate on new findings only |
| Scans add 5+ minutes | Running in series, downloading the DB each time | Parallel jobs, cached Trivy DB, diff-aware SAST |
| Developers ignore results | Findings land in a dashboard or report | SARIF annotations on the pull request |
| Releases blocked by unfixable CVEs | Gating on CVEs with no patched version | --ignore-unfixed, plus nightly tracking |
| Ignore lists grow forever | Exceptions with no owner or expiry | Reason, owner and expiry on every exception |
How iDefender does this
We run this as a fixed rollout: pipeline review, then warn-only scanning, then staged gates at thresholds we agree with your team. A typical first phase takes 4 to 8 weeks. The core stack is Semgrep, Trivy, OWASP ZAP for dynamic testing against staging, Vault for secrets and OPA for policy as code. Scan results, approvals and deployment records are kept automatically as audit evidence. See DevSecOps services or book a call.
Frequently asked questions
Will security scanning slow down our CI pipeline?
Not noticeably if the scans run as parallel jobs, SAST scans only the pull request's changes, and the vulnerability database is cached. Full scans move to a nightly schedule, so pull requests carry only the fast path.
Should a vulnerability scan block the merge?
Block only on new high or critical findings that have a fix available. Report everything else. Blocking on unfixable or pre-existing findings teaches developers to bypass the gate.
Do we need SAST and dependency scanning, or is one enough?
Both. SAST checks the code your team wrote; dependency scanning checks the third-party code you import, which is most of what you ship. They find different problems and don't overlap much.
Is Trivy enough for container scanning?
For most teams, yes. Trivy covers OS packages, language dependencies inside the image and Dockerfile misconfiguration in one open-source tool. Teams that want a second opinion often add Grype; commercial platforms add reachability analysis and central reporting.
How do we handle false positives?
Mark them in the repository (nosemgrep with a reason, .trivyignore with an owner and expiry date) so the decision is reviewed in code like any other change, and revisit the list monthly.

