Skip to main content

SAST

SAST (Static Application Security Testing) analyses source code for security flaws without running it, so vulnerabilities are found in pull requests before release.

Understanding SAST

What Is SAST and What Does It Catch

SAST tools parse your source code into a syntax tree and trace how data flows from untrusted inputs to dangerous operations. They flag issues such as SQL injection, command injection, hardcoded secrets, weak cryptography, and path traversal. Because the code is never executed, scans run early and cheaply, on every pull request.

Where SAST Fits

flowchart LR A[Pull request] --> B[SAST scan] B --> C{HIGH finding?} C -->|Yes| D[Block merge] C -->|No| E[Merge and continue] classDef start fill:#8B5CF6,color:#FFFFFF classDef scan fill:#326CE5,color:#FFFFFF classDef bad fill:#EF4444,color:#FFFFFF classDef good fill:#10B981,color:#FFFFFF class A start class B,C scan class D bad class E good

SAST complements, not replaces, DAST (testing a running app), dependency scanning, and secret scanning.

Semgrep in GitHub Actions

YAML
jobs:
semgrep:
runs-on: ubuntu-latest
container:
image: semgrep/semgrep
permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@v4
- name: Scan
run: >
semgrep scan
--config p/owasp-top-ten
--config p/secrets
--severity ERROR
--error
--sarif --output semgrep.sarif
- uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: semgrep.sarif

The --error flag returns a non-zero exit code on findings, which makes the step block the pipeline. GitHub's CodeQL is an alternative for deeper analysis in supported languages.

A Custom Semgrep Rule

YAML
rules:
- id: unsafe-query-construction
pattern: db.query("..." + $INPUT)
message: Use parameterised queries, for example db.query(sql, [params]).
severity: ERROR
languages: [javascript]

Practical Commands

Bash
pip install semgrep
semgrep scan --config p/secrets .
semgrep scan --config p/owasp-top-ten --json src/ \
| jq '.results[] | {file: .path, line: .start.line, message: .extra.message}'

Troubleshooting

Symptom Check What to look for
Too many false positives Rulesets used Broad rules to disable or tune
Blocking on old code Baseline support Compare against the base branch
Scan too slow Rule count Targeted rulesets, not all rules
Tip

Start with a secrets ruleset. It has low false-positive rates and catches real critical issues, then add broader rulesets once the team trusts the gate.

Remember

A finding is a signal, not a verdict. Triage whether untrusted input really reaches the sink.

Security

Block only on HIGH and CRITICAL findings. Blocking on noise leads to the scanner being disabled or set to continue-on-error.

Common Mistake

Running SAST as a report-only step. If findings never block, people stop reading them within a week.

Frequently Asked Questions

What does SAST find that code review often misses?

Data-flow problems that span files and functions, such as tainted input reaching a SQL query or shell command. Tools trace these paths systematically, which is tedious for humans on a large codebase.

Why do teams end up ignoring SAST results?

Default rules create false positives and low-severity noise. Tune rules to the codebase, block only on high-confidence and high-severity findings, and send the rest to a dashboard.

What is the difference between SAST and DAST?

SAST reads the source without running it and finds issues early. DAST probes a running application from outside and finds runtime and configuration issues. Most teams use both.

Found a mistake, an outdated step or a broken link?