A type of security analysis. Verifies software without running it.
Analysis Scope
Analysis Targets
Static analysis can inspect:
- Source code
Gives more context through variable names and comments. It also allows fixing found problems and is hard to decompile. - Executables
Needed when source is unavailable, or when the built artifact differs from source.
Human Analysis
Human analysis is strong on context and intent. It is expensive, time-consuming and prone to boredom.
Inspection Roles
IEEE 1028 assigns 5 roles to an inspection. Roles may be shared.
- Inspection Leader
Plans the inspection, conducts it, ensures it meets its objectives, and issues its output. - Recorder
Documents anomalies, action items, decisions, and recommendations. - Reader
Guides the team through the artifact in a logical order and highlights important parts. - Author
Explains the artifact, ensures it meets entry criteria, and performs the required rework. Cannot be the inspection leader. Should not be the reader or recorder. - Inspector
Identifies and describes anomalies from a relevant viewpoint, such as requirements, design, code, test, or safety. All participants are inspectors.
Code Quality Checks
Type Checker
Not security-specific but useful. Finds inconsistent use of values and unsafe conversions.
Compiler Warnings
Not all warnings are security related. But they ensure correctness of the code. It is recommended to enable them. Even though warnings are not high priority, they should be fixed early on, so that new warnings stand out.
Examples:
- GCC, the C compiler, has
-Wall -Wextra. - JavaScript has
use strict -Wimplicit-fallthroughin Linux found real bugs in about 10% of the fall-through patches it prompted.
Unreachable Code Detection
Unreachable code (also known as dead code) is the code block that cannot execute because the surrounding control flow does not allow it to. Has no runtime effect. Indicates an error in the program’s logic.
Common causes:
- Unconditional transfer
A precedingreturn,throw,break,continue, orgotoexits the path first. - Impossible condition
A condition is always true or always false because of earlier assignments or contradictory tests. - Unused entry point
A private function has no callers, or a callback is never registered.
Dead code becomes security-relevant when it contains a required check. Unreachable input validation, authentication, authorization, or certificate validation leaves the protected operation exposed. It also makes code harder to maintain because reviewers may mistake the dead path for active protection.
The fix is either:
- Correct the control flow
If it must execute. - Remove the deadc code
If it must not execute. For the sake of completeness.
Examples:
- Apple’s
goto failbug
A duplicatedgoto fail;skipped certificate validation and allowed an adversary-in-the-middle attack.
Linter
Compares source to pre-canned rules. Does not targets security.
Examples:
- PMD for Java source.
- SpotBugs for JVM bytecode.
- FindSecurityBugs, a SpotBugs security plugin.
Security Defect Detection
Security Defect Text Scanners
Grep-like lexers that look for dangerous function calls. Fast, cheap, and work on partial code. Have high false positive and false negative rates.
Examples:
- Flawfinder
- RATS
- ITS4
Security Defect Finders
Security defect finders build an internal model and look for vulnerability patterns. Many aim to be sound.
- Taint propagation
Tracks untrusted input from sources to sinks and warns when it reaches a sink unsanitized. Especially useful for injection and buffer overflow. - Control flow analysis
Follows execution paths to find dangerous sequences like double-free. - Property checkers
Prove a narrow temporal safety property, for example always freeing allocated memory.
Examples:
- Coverity
- Fortify
- cppcheck
- clang static analyzer
Repository Analysis
Software Composition Analysis
Also known as Origin analysis. Identifies embedded libraries and flags those with known vulnerabilities. It cross-references the NIST National Vulnerability Database. Prefer package-manager data for low false positives.
Secret Scanners
Secret scanners look for accidentally committed passwords and private keys. They are built into GitHub and GitLab.