4. Review Code-Level Vulnerabilities (overview)
Chapter 4 - Review Code-Level Vulnerabilities
Code-level security analysis is the final layer of the methodology.
The methodology chapter defined structure, modeled subsystem threats, traced data, and checked business logic. This part moves into the code that implements the security controls. The reviewer now asks how individual variables, functions, libraries, parsers, and framework calls can turn attacker-controlled input into security impact.
The goal is not to memorize every bug class. The goal is to learn a repeatable pattern: trace the data, identify the trust boundary, find the unsafe assumption, and verify the control.
How to Use the Mini-Chapters
Each vulnerability family below has its own standalone chapter. Every mini-chapter follows the same teaching pattern:
- What the flaw is — definition and CWE mapping where applicable.
- Vulnerability characteristics — where the pattern appears in real codebases (features, sinks, weak controls).
- Attack payloads (or abuse scenarios) — representative test patterns for authorized security testing.
- Language-specific sinks and dangerous APIs — per-language libraries, calls, and system interfaces to search for, each with a short code sample.
- Sample vulnerable code in Python — one focused example to study first.
- Step-by-step review walkthrough — how to trace the flaw and why each step matters.
- Risk impact analysis — what can go wrong for users, data, and the business.
- Vulnerable examples in other languages — always Java and C# first; then, when applicable, JavaScript, HTML, and Go; then SQL, Shell, and C. The Sample Vulnerable Code section always uses Python for the primary walkthrough.
- Fix: safer patterns and libraries — real code using vetted APIs, with Important notes per language.
- Verify during review — evidence to collect before you file a finding.
- Reference — official documentation links for the libraries and standards cited in the fix section.
The archive article Secure Coding in Practice remains available as background reading; mini-chapters do not link to it in their reference sections.
Code diversity across examples
Examples are intentionally varied across chapters. The same function call (for example subprocess with shell=True, jwt.decode(..., verify_signature=False), or a generic ping wrapper) should not repeat in another mini-chapter unless this page shows a vulnerable pattern paired with a fixed contrast in the same section. Prefer different libraries, business scenarios, and sink APIs so readers see a wider attack surface—not one canonical snippet copied everywhere.
Input Validation, Injection, and Parsing
- 4.1 Review Stored XSS
- 4.2 Review Reflected XSS
- 4.3 Review SQL Injection
- 4.4 Review Command Injection
- 4.5 Review Code Injection
- 4.6 Review JSON Injection
- 4.7 Review Dynamic JSP Inclusion
- 4.8 Review XXE
- 4.9 Review SSTI
- 4.10 Review Path Traversal
- 4.11 Review Client-Side Validation
Cryptography
Sessions, Requests, and Access Control
- 4.13 Review CSRF
- 4.14 Review SSRF
- 4.15 Review Broken Session Management
- 4.16 Review JWT Security
- 4.17 Review Authentication and Authorization
- 4.18 Review Broken Password Lifecycle
- 4.19 Review Forced Browsing
- 4.20 Review IDOR
Information Disclosure
- 4.21 Review Error Page Disclosure
- 4.22 Review Sensitive Data in URL
- 4.23 Review Username Enumeration
- 4.24 Review Internal and Egress Exfiltration
- 4.25 Review Sensitive Logging
File and Path Handling
- 4.26 Review Insecure Temporary Files
- 4.27 Review Insecure File Parsing
- 4.28 Review Insecure File Path Handling
- 4.29 Review Insecure File Upload
Framework and Configuration
Insecure Coding Practices
- 4.41 Review Insecure Coding Practice — TLS verification, JWT signature/key handling, cookie flags, and related habits
- 4.31 Review Sensitive Code Comments
- 4.32 Review Hardcoded Secrets
- 4.33 Review Insecure Cookie Configuration
- 4.34 Review Obsolete Code
- 4.35 Review Dangerous Functions
- 4.36 Review Non-Standard Crypto Practices
- 4.37 Review Insecure Deserialization
- 4.38 Review Encryption and Decryption Mistakes
Logging and Supply Chain
Core Review Habits
Most code-level findings still start with data flow:
- Where does the data come from?
- What code transforms it?
- Where is it used (the sink)?
- Is the data attacker-controlled?
Separate input validation from output encoding. Validation decides whether data is acceptable for the application. Encoding makes data safe for a specific output context (HTML, SQL, shell, URL).
When you finish a mini-chapter, record source, sink, missing control, impact, and a test that proves the fix.
Next: Secure Implementations and Configuration
After code-level patterns, continue with:
- Chapter 10 - Review Secure Implementations — OAuth, OIDC, JWT, SAML, TLS, mTLS, API signing
- Chapter 11 - Review Secure Configuration — Snowflake, Databricks clean rooms, AWS IAM, Kubernetes, PostgreSQL