DevSecOps

SAST Tools: Static Application Security Testing

Intermediate
16 minutes
Updated October 2026

Compare and implement SAST tools — SonarQube, Semgrep, Snyk, and CodeQL — in your CI/CD pipeline. This guide covers what each tool is actually good at, how to wire them in, and how to survive the first scan on a legacy codebase.

Table of Contents

What SAST Does

SAST analyzes source code (or compiled binaries) without running it to find:

  • SQL injection, XSS, command injection
  • Hardcoded credentials and secrets
  • Insecure crypto usage
  • Buffer overflows (C/C++)
  • Framework-specific misconfigurations

It runs fast and early — catch bugs before code review, not in production. Because it works statically, it covers every code path, not just the ones your tests exercise — a SQL injection in an error handler that never runs in staging still gets flagged.

What SAST Doesn't Do

SAST is necessary but not sufficient:

  • It can't see runtime behavior — authentication bypasses, business-logic flaws, and misconfigurations that only manifest when the app runs need DAST or manual testing.
  • It produces false positives — pattern-matching on code can't always tell "user input that's been sanitized" from "user input that hasn't." Expect to triage.
  • It doesn't cover your dependencies — that's SCA's job (Snyk, Dependabot, npm audit). SAST scans your code; SCA scans their code.
  • It's only as good as its rules — a tool without a rule for your framework's foot-gun won't find your framework's foot-gun.

The point of naming the limits: teams that treat SAST as "the security tool" get a false sense of coverage. It's one layer of several.

Tool Comparison

ToolTypeLanguagesBest ForFree Tier
SonarQubeServer + scanner30+Teams wanting dashboards & quality gatesCommunity edition
SemgrepCLI rules engine30+Custom rules, fast CI, polyglot codebasesOpen source
CodeQLGitHub-native9GitHub repos, deep semantic analysisFree on public repos
SnykCloud SaaSManyDev-first UX, fix advice, dep scanningLimited free scans
CheckmarxEnterprise SaaS35+Compliance-heavy orgsTrial only
BanditCLIPython onlyPython projectsOpen source
GitleaksCLI secretsAny textSecrets detection specificallyOpen source

The practical breakdown: Semgrep if you want speed and custom rules, SonarQube if you want dashboards and team-wide quality gates, CodeQL if you're on GitHub and want the deepest analysis for free, Snyk if developer UX and fix suggestions matter more than self-hosting.

Quick Start Guides

Semgrep (Fastest to Set Up)

# Install
pip install semgrep

# Scan with community rules
semgrep scan --config auto .

# Scan with specific ruleset
semgrep scan --config p/security-audit .

CI-friendly — one command, JSON output, exit code reflects findings. --config auto picks rules for the languages it detects; p/security-audit is the curated security set.

SonarQube

# Start local SonarQube
docker run -d -p 9000:9000 sonarqube:community

# Scan with sonar-scanner
sonar-scanner \
  -Dsonar.projectKey=my-app \
  -Dsonar.sources=. \
  -Dsonar.host.url=http://localhost:9000 \
  -Dsonar.login=$SONAR_TOKEN

SonarQube's value is the server, not the scan — it tracks findings over time, shows trend dashboards, and enforces quality gates ("no new critical issues on this PR") rather than just listing problems.

CodeQL (GitHub Native)

# .github/workflows/codeql.yml
name: "CodeQL"
on: [push, pull_request]
jobs:
  analyze:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: github/codeql-action/init@v3
        with:
          languages: javascript-typescript
      - uses: github/codeql-action/analyze@v3

CodeQL builds a semantic model of the code and queries it — deeper than pattern matching, so it finds multi-step vulnerabilities (user input flowing through three functions into a sink) that regex-style tools miss. Free on public repos; on private repos it needs GitHub Advanced Security.

Bandit (Python)

pip install bandit
bandit -r . -f json -o bandit-report.json

Python-only but sharp on Python-specific issues (pickle usage, subprocess with shell=True, weak crypto). Worth adding alongside a polyglot tool on Python projects — language-specific linters catch idiomatic issues the generalists don't have rules for.

CI/CD Integration

Jenkins Pipeline

stage('SAST Scan') {
    steps {
        sh '''
            semgrep scan --config auto . \
              --json -o semgrep-results.json || true
        '''
        archiveArtifacts 'semgrep-results.json'
    }
}

GitHub Actions

- name: Run Semgrep
  uses: semgrep/semgrep-action@v1
  with:
    config: p/security-audit
    generateSarif: true
- name: Upload SARIF
  uses: github/codeql-action/upload-sarif@v3
  with:
    sarif_file: semgrep.sarif

SARIF uploads land findings in the Security tab with PR annotations — developers see the issue on the exact line, in the review they're already doing.

Quality Gate

# Block merges on new critical findings
- name: Check findings
  run: |
    CRITICAL=$(jq '[.results[] | select(.extra.severity == "ERROR")] | length' report.json)
    if [ "$CRITICAL" -gt 0 ]; then
      echo "::error::$CRITICAL critical findings"
      exit 1
    fi

Triage and Baseline

First scan on a legacy codebase will show hundreds of findings. Don't panic — this is the expected experience, and the reason most SAST rollouts die:

Step 1: Baseline

# Accept current state, only flag new issues
semgrep scan --config auto --baseline-commit main .

Baseline mode is the adoption unlock: existing findings become background (tracked, not blocking), and only new code gets gated. The team sees a tool that helps, not a wall of inherited guilt.

Step 2: Suppress False Positives

# Inline suppression with justification
query = f"SELECT * FROM users WHERE id = {user_id}"  # nosemgrep: user input validated upstream

Suppression comments need a reason, not just nosemgrep — the justification is what makes a reviewer pause on a genuinely dangerous suppression.

Step 3: Custom Rules

# rules/no-eval.yml — block eval() in your codebase
rules:
  - id: no-eval
    pattern: eval(...)
    message: "eval() is banned in this codebase"
    severity: ERROR
    languages: [python, javascript]
semgrep scan --config rules/ .

Custom rules are where SAST gets genuinely good — your codebase has patterns the generic rules can't know (a forbidden internal API, a required auth wrapper). Semgrep rules are YAML patterns, not a language, so writing them is an afternoon not a project.

Best Practices

1. Scan Every PR, Not Just Main

on: [push, pull_request]    # catch issues before merge

Findings on a PR are code review — the author still has context. Findings on main are backlog items that never get read.

2. Combine SAST with Other Scans

LayerTool Type
Code quality + vulnsSAST (Semgrep/SonarQube)
SecretsGitleaks, TruffleHog
DependenciesSnyk, Dependabot, npm audit
ContainersTrivy
RuntimeDAST (OWASP ZAP)

Each tool covers what the others can't — SAST finds the SQL injection in your code, SCA finds it in a library, DAST finds it in the running app.

3. Tune Severity, Don't Disable

Disable noisy rules rather than whole scans:

# .semgrepignore
tests/
migrations/
*.min.js

4. Track Metrics Over Time

  • Findings per KLOC trending down = healthy
  • Mean time to remediate < 30 days
  • Zero critical findings older than SLA

Metrics turn "we added SAST" into "SAST is working" — findings-per-thousand-lines trending down is the signal that the tool is driving fixes, not just generating reports.

5. Developer-Friendly Output

# Human-readable summary, not just JSON
semgrep scan --config auto . --output report.txt

A finding that says "possible SQL injection — user input reaches query without parameterization" with a link to the fix gets fixed. A JSON blob does not.

Common Pitfalls

  • Scanning everything every commit — scope to changed files with --baseline-commit or your CI time balloons
  • No baseline on legacy code — drowning in old findings kills adoption before it starts
  • SAST alone — misses runtime issues; pair with DAST and dependency scanning
  • Ignoring developer feedback — tune rules quarterly based on false-positive reports, or developers learn to ignore the tool
  • Gating on everything — fail on critical, warn on the rest; a build that fails on medium findings gets bypassed within a week
Written & Reviewed by Yasir Masood, CloudOpsGuide Editor

Our tutorials and troubleshooting runbooks are written by a DevOps practitioner with hands-on experience operating Kubernetes, Terraform, CI/CD pipelines, and Linux infrastructure in production. Commands, manifests, and configurations are verified against current tooling releases. Learn more about our editorial process or report a correction or outdated flag.