Source Code Review & SAST
Reading code for security defects, and the static analysis that points you at the code worth reading. Nine chapters, from taint analysis to the tool licensing traps that decide what your team can actually run.
White-box vs black-box
Source code review methodology - scope, map, scan, review, validate, fix
Scroll sideways to see the whole diagram
The same flow, in text
1. Reconnaissance
Read the layout before you read the code: frameworks, entry points, trust boundaries, and every place untrusted data enters the system.
2. Automated scanning
Run Semgrep, CodeQL or SonarQube to clear the low-hanging fruit and to rank which files are worth reading by hand.
3. Manual review
Work authentication, authorisation, input handling, cryptography and business logic by hand. Trace source to sink; a pattern match is not a path.
4. Validation
Reproduce the finding in a test environment. A path you cannot demonstrate is a hypothesis, not a finding.
5. Remediation guidance
Hand the developer a minimal fix and the test that proves it, not just a CWE number and a severity label.
Where to Start
The chapters run in a deliberate order: method first, then one language at a time, then the tooling that automates it, then what you do with the findings. If you only read two, read 2 and 8.
What a Review Finds
Four classes cover most of what lands in a source review report. Each card is tagged with its OWASP Top 10:2025 category; the language chapters show what the pattern looks like in real code.
Injection sinks
Untrusted input reaching an interpreter without a parameterised boundary.
- SQL built by string concatenation
- os.system / Runtime.exec / child_process
- LDAP, NoSQL and template injection
Access control gaps
Checks that are missing, client-side only, or applied to the wrong object.
- Object references trusted from the request
- Authorisation enforced in the UI only
- Mass assignment of privileged fields
Integrity failures
Data or code accepted without proving where it came from or that it is intact.
- Unsafe deserialisation of untrusted bytes
- Unsigned updates and plugin loading
- Unverified third-party artefacts
Secrets and supply chain
Credentials in the repository and dependencies nobody verified.
- Hardcoded keys, tokens and passwords
- Committed .env and private key material
- Unpinned or unverified dependencies
Tooling: What the Free Tier Actually Gives You
The "free" column is where most tool comparisons go wrong. Each row below states the edition, because the edition is what changes the answer: a licence that forbids embedding, a free tier without branch analysis, or a scanner that will not touch a private repository. Full setup for each is on page 8.
| Tool | Licence | Languages (as the vendor states) | Free-tier reality | Best for |
|---|---|---|---|---|
| SonarQube Community Build | LGPL-3.0 | Sonar's own pages disagree: 22 on the product page, 40+ in the docs. Quote the edition, never a bare count. | Free, no LOC ceiling. No branch or PR analysis, which is the paid split (SonarQube Server / Cloud). | A self-hosted quality and security gate on one server. |
| Semgrep CE | LGPL-2.1 engine. The rules are not open source: Semgrep Rules License v1.0, internal business use only. | CE README says 30+, product docs say 35+. CE analyses one file at a time. | Free engine, but interfile dataflow is the commercial engine and the rule registry is licensed. | Fast custom pattern rules in CI, plus taint mode within a single file. |
| CodeQL | Proprietary. The CLI licence covers academic, demo and OSI-licensed codebases only. | 10: C/C++, C#, Go, Java/Kotlin, JS/TS, Python, Ruby, Rust, Swift, Actions. No PHP, no Scala. | Public repos only on Free/Pro. Private and internal repos need GitHub Code Security (Team/Enterprise). | Deep dataflow analysis of GitHub-hosted open source. |
| Checkmarx One | Commercial. Legacy CxSAST naming is retired; Checkmarx Fusion is the 2026 hybrid engine. | Vendor-stated only, and not comparable with the free tools above. | No free tier. Trial or paid seats. | Enterprise portfolios that need policy, reporting and vendor support. |
| gitleaks / TruffleHog / SCA | gitleaks MIT, TruffleHog AGPL-3.0. The AGPL is a real blocker for embedding in closed-source tooling. | Language-agnostic: regex and entropy for secrets, lockfile parsing for dependencies. | Both free and self-hostable, which is why the licence, not the price, is the decision. | Secrets and dependency CVEs. Covered in full on page 8. |
No authoritative false-positive rate exists for SAST. Vendor figures are self-reported and not comparable, so measure recall and noise against the OWASP Benchmark on your own codebase before you pick a gate.
Scope and Prerequisites
This section teaches review and static analysis. It assumes you can read the code you are assessing, under written authorisation, and that you have somewhere safe to reproduce a finding.
In scope
- SAST methodology, taint analysis and the limits of automated review
- Manual review for Java/Spring, C#/.NET, Python, JavaScript and Go
- Tool selection, licensing traps, and CI wiring
- Secret scanning and dependency review
- Triage, evidence, developer handoff and regression tests
Elsewhere on the site
- Runtime exploitation and live testing - see Web Penetration Testing
- Deep fix recipes - see Remediation Guidance
- Design review and threat modelling - see Secure Architecture
- Pipeline and dependency hardening - see CI/CD and Supply Chain
You will need: a machine you can install tooling on, Docker for the self-hosted scanners, and one open-source codebase you know well. OWASP Benchmark, Juice Shop and NodeGoat are all seeded with known defects, so you can check whether a tool or a reviewer actually found them.
Related Source Code Review Guides
Web Penetration Testing
Black-box testing of the running system these findings live in
API Pentesting
BOLA, mass assignment and injection tested from the outside
CI/CD & Supply Chain
Pipeline security and dependency integrity controls
Secure Architecture
Design review and trust boundaries, before code exists
Remediation Guidance
The fix catalogue for the vulnerability classes reviewed here
Reporting Templates
Finding write-ups that survive developer review