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
SAST complements, not replaces, DAST (testing a running app), dependency scanning, and secret scanning.
Semgrep in GitHub Actions
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.sarifThe --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
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
pip install semgrepsemgrep 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 |
TipStart 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.
RememberA finding is a signal, not a verdict. Triage whether untrusted input really reaches the sink.
SecurityBlock only on HIGH and CRITICAL findings. Blocking on noise leads to the scanner being disabled or set to continue-on-error.
Common MistakeRunning 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.