SAST
SAST: Static Application Security Testing
SAST checks source code for vulnerabilities without running the application. The analyzer reads code the way an experienced reviewer would, only faster and across the whole project at once. It builds a model of the program and looks for places where unchecked data reaches a dangerous function.
Its main advantage is early detection. A problem shows up in the pull request, down to the file and line, when it is cheapest to fix.
How it works
- Parse the code into a syntax tree and a control-flow graph.
- Taint analysis: trace data from a source (request parameter, file, queue message) to a sink such as an SQL query, an OS command or an HTML template.
- Rule-based search: dangerous functions, weak cryptography, hardcoded secrets, unsafe deserialization.
- The result is a list of findings with the vulnerability type (CWE), severity and location in the code.
What it finds
| SQL injection | CWE-89 | User input is concatenated into the query text |
| Cross-site scripting (XSS) | CWE-79 | Data is written to HTML without escaping |
| OS command injection | CWE-78 | A parameter reaches a shell call |
| Path traversal | CWE-22 | A file name from the request is opened without validation |
| Secrets in code | CWE-798 | A password, token or key is written directly in the source |
| Weak cryptography | CWE-327 | MD5, SHA-1, DES, ECB, a home-made cipher |
| Insecure deserialization | CWE-502 | An object is restored from untrusted data |
Example
String sql = "SELECT * FROM accounts WHERE iban = '"
+ request.getParameter("iban") + "'";
ResultSet rs = conn.createStatement().executeQuery(sql); PreparedStatement ps = conn.prepareStatement(
"SELECT * FROM accounts WHERE iban = ?");
ps.setString(1, request.getParameter("iban"));
ResultSet rs = ps.executeQuery(); CWE-89 · SQL Injection · AccountController.java:42 · source request.getParameter("iban") → sink Statement.executeQuery
Limitations and common mistakes
- False positives: the analyzer does not know the business logic, so some findings need manual review.
- It cannot see server misconfiguration or problems that appear only at runtime. DAST covers those.
- It does not check third-party libraries. That is the job of SCA.
How to choose a SAST tool
- Languages and frameworks: the analyzer must understand every language in the project. Check niche ones separately: 1C, PL/SQL, Kotlin, Swift, Dart.
- Checking changes in a merge request within minutes, not only a full scan at night.
- Triage: suppressing false positives with a recorded reason, so they do not come back after the next scan.
- Custom rules: the ability to add checks for internal libraries and requirements.
- Where it runs: in an isolated environment the code must not leave for an external cloud.
- Reports mapped to CWE and OWASP Top 10, which auditors and regulators ask for.
SAST, SCA and DAST: what is the difference
| SAST | SCA | DAST | |
|---|---|---|---|
| What it checks | Your own source code | Third-party libraries | The running application from outside |
| Needs a run | No | No | Yes, a test environment |
| When | Every merge request | Every build and on a new CVE | On a test environment before release |
| Finds | Injections, XSS, secrets, weak cryptography | Known CVEs, licenses, malicious packages | Configuration, authentication and header errors |
| Does not see | Other people's libraries, server configuration | Errors in your code | The exact place in the code |
Tools
Questions and answers
How is SAST different from DAST?
SAST looks at source code without running it. DAST tests the running application from the outside. They find different classes of problems and complement each other.
Is one SAST scanner enough?
One engine has its own blind spots. Different analyzers are strong in different languages and vulnerability classes, so teams often run several together and merge the results, removing duplicates.
When should SAST run?
On every pull request or commit as a fast check of the changes, and regularly as a full scan of the whole repository.
What is static code analysis?
Checking a program from its source text without running it. In the broad sense it covers both code quality checks (linters) and vulnerability search. SAST is static analysis aimed specifically at security.
Does SAST work for mobile apps?
Yes. Analyzers check source code in Kotlin, Java, Swift, Objective-C and Dart. Typical mobile findings are insecure data storage on the device, disabled certificate validation and keys in code. Checks of the built APK or IPA are complemented by dynamic analysis and OWASP MASVS requirements.
Do I need SAST if I have SCA?
Yes. SCA checks third-party libraries and SAST checks your own code. SCA will not see a vulnerability in your team's code, and the reverse is also true.