references/common-vulnerability-patterns.md
GitHubCommon Vulnerability Patterns
Use this reference during manual review when a code path reaches a common security sink or security decision. Base findings on concrete sources, transformations, controls, and sinks rather than on pattern matching alone.
Contents
- Input validation
- Injection
- Authentication and session management
- Access control
- Deserialization and XML
- Cryptographic implementation
- OWASP source map
Input Validation
Review all externally influenced inputs, including browser requests, API calls, files, queues, partner feeds, webhooks, and configuration values that can cross a trust boundary.
Check for:
- missing server-side validation or reliance on client-side checks
- validation performed after parsing, persistence, rendering, or another dangerous sink
- denylist-only filtering instead of allowlists for structured fields
- missing syntactic validation for types, formats, lengths, ranges, and enumerated values
- missing semantic validation for business rules such as date ordering, amount bounds, tenant ownership, or state transitions
- inconsistent normalization or Unicode handling before comparison, lookup, or policy checks
- weak regexes that do not anchor the full input or that introduce ReDoS risk
- upload flows that trust filenames, extensions, headers, archive paths, or user-selected storage locations
Expect:
- validation as early as possible after data crosses the boundary
- server-side enforcement even when client-side validation exists for UX
- allowlists for structured inputs and fixed option sets
- explicit minimum and maximum lengths, numeric ranges, and schema checks
- sink-specific defenses in addition to validation; do not treat input validation as the primary defense for SQL injection or XSS
Injection
SQL Injection
Look for:
- string concatenation, interpolation, or format strings in SQL statements
- dynamic WHERE, ORDER BY, LIMIT, table, or column fragments built from user input
- stored procedures that concatenate query text internally
- ORM escape hatches that accept raw query fragments
Expect:
- prepared statements or parameterized queries for data values
- safely constructed stored procedures only when they preserve parameterization
- allowlists for unavoidable identifiers or sort directions that cannot be bound as values
- escaping only as a last-resort supplemental control, not the primary defense
Cross-Site Scripting
Look for:
- untrusted data rendered into HTML, attributes, JavaScript, CSS, URLs, templates, or client-side DOM operations
- unsafe DOM sinks such as
innerHTML,outerHTML,document.write, or string-built event handlers - rich-text rendering without a dedicated sanitization library
- output encoding that does not match the destination context
- code that relies only on CSP or framework defaults while bypassing their safe rendering APIs
Expect:
- context-appropriate output encoding at the final rendering sink
- safe DOM sinks such as
textContentorvaluewhere possible - hardcoded innocuous attribute names when assigning attributes
- dedicated HTML sanitization for intentionally allowed rich content
Path Traversal and File Handling
Look for:
- user-controlled path segments, filenames, archive member names, or temporary file names
- path joins that accept
.., absolute paths, encoded traversal, or alternate separators - upload handlers that let the client choose storage paths or preserve attacker-controlled filenames
- archive extraction without validating target paths and expanded size
- files stored inside the webroot or with executable permissions without a clear requirement
Expect:
- server-generated storage names and server-selected storage paths
- allowlisted file types plus content-based validation where files are accepted
- storage outside the webroot or on a separate host when possible
- least-privilege filesystem permissions
- explicit checks before archive extraction and downstream processing
Command Injection
Look for:
- shell execution, process spawning, or system utilities that receive user-controlled input
- string-built commands, shell metacharacters, and user-selected executable names or flags
- code that escapes shell input but still allows argument injection
- privileged processes invoking commands when a library API would suffice
Expect:
- library APIs instead of OS commands whenever possible
- structured process APIs that keep the executable and each argument separate
- allowlists for commands and arguments when commands cannot be avoided
- end-of-options handling where supported, such as
--before attacker-influenced operands - least-privilege execution and isolated service accounts
NoSQL Injection
Look for:
- raw client objects or operators merged into NoSQL queries
- string-built query-language expressions or JavaScript evaluation features
- attacker control over operators such as
$where, comparison operators, or aggregation stages - untyped query construction and missing parameter binding in drivers or ODMs
- administrative interfaces or databases exposed without authentication
Expect:
- typed, structured driver or ODM query APIs
- explicit allowlists for accepted fields, operators, filters, and sort keys
- schema and type validation before query construction
- rejection of raw operator objects and executable query fragments from clients
Authentication and Session Management
Review identity establishment, credential handling, session creation, session renewal, logout, password reset, account recovery, and re-authentication for sensitive operations.
Check for:
- inconsistent authentication enforcement across routes, RPC methods, background jobs, and alternate entry points
- credentials or authentication tokens logged, persisted insecurely, or transmitted outside TLS
- verbose login or recovery responses that reveal account existence
- missing re-authentication after password resets, recovery, suspicious activity, or privilege-sensitive actions
- weak session identifiers, predictable values, or tokens containing sensitive data
- session IDs accepted through URLs or alternate channels when cookies are the intended mechanism
- missing
Secure,HttpOnly, orSameSitecookie settings where browser cookies are used - sessions that are not invalidated on logout, timeout, password change, or account state change
- session IDs not regenerated after authentication or any privilege level change
Expect:
- generic authentication failure responses
- strong password storage and secure transport for credentials
- cryptographically random session IDs with sufficient entropy and meaningless client-side contents
- cookie-based session exchange over TLS with secure cookie attributes
- strict session handling that rejects IDs the server did not generate
- session renewal on authentication and privilege transitions
Access Control
Model authorization as subject, action, object, tenant, and environment conditions. Verify both horizontal and vertical privilege boundaries.
Check for:
- missing object-level checks after a user is authenticated
- role checks without ownership, tenant, relationship, or resource-state checks
- authorization enforced only in the UI or client
- predictable or tamperable identifiers used without resource authorization
- alternate routes, exports, batch handlers, static resources, or background jobs that bypass the normal policy layer
- fail-open behavior on missing policy data, exceptions, or framework misconfiguration
- permissions broader than required for the user or service role
Expect:
- deny-by-default behavior
- server-side authorization on every request and every sensitive state transition
- least privilege across users, services, and administrative functions
- centralized policy decisions with explicit object-level and tenant-level checks
- safe failure handling and audit logging for denied access
- regression tests for unauthorized reads, writes, and privilege changes
Deserialization and XML
Insecure Deserialization
Look for:
- native object deserialization of untrusted input from requests, cookies, queues, caches, files, or database fields
- deserializers that let the data stream choose the target type or class
- unsafe library modes, polymorphic type handling, gadget-capable formats, or domain objects that should never be deserialized
- signed data that is verified after deserialization instead of before it
Expect:
- safer data formats and explicit schemas instead of native object graphs where possible
- strict allowlists for allowed types when deserialization is unavoidable
- integrity verification before deserialization when signed payloads are used
- language-specific hardening for high-risk APIs and libraries
XML External Entity
Look for:
- XML parsers that accept untrusted XML without explicit parser hardening
- DTD support, external entity resolution, external DTD loading, XInclude, or schema imports from untrusted locations
- XML inputs that can reach filesystem reads, internal network requests, or parser expansion behavior
Expect:
- DTDs disabled completely whenever possible
- external entities and external DTD loading disabled when DTD support cannot be removed
- parser-specific hardening verified in the actual library and version in use
- regression tests for file disclosure, SSRF, and entity expansion payloads
Cryptographic Implementation
Review the protected asset, threat model, algorithm choice, mode, randomness, key lifecycle, and failure behavior together.
Check for:
- custom cryptographic algorithms or protocols
- outdated algorithms, weak key sizes, ECB mode, unauthenticated encryption, or insecure padding choices
- hardcoded keys, reused IVs or nonces, predictable randomness, or keys stored beside ciphertext
- missing certificate validation or hostname verification
- encryption used without integrity protection
- tokens, reset links, IVs, session IDs, or keys generated with non-cryptographic randomness
- missing key rotation, separation, revocation, or access controls
Expect:
- standard, maintained cryptographic libraries
- AES with an authenticated mode such as GCM or CCM for symmetric encryption where applicable
- modern asymmetric choices such as Curve25519, or RSA with at least 2048-bit keys when RSA is required
- secure random generation for keys, IVs, nonces, session IDs, and recovery tokens
- key storage and rotation designed separately from ciphertext storage
- explicit integrity and authenticity checks in addition to confidentiality
Detailed Local References
Use these local references instead of retrieving the upstream cheat sheets during ordinary reviews:
- owasp-secure-code-review.md
- owasp-input-validation.md
- owasp-sql-injection.md
- owasp-xss.md
- owasp-file-upload.md
- owasp-os-command-injection.md
- owasp-nosql-security.md
- owasp-authentication.md
- owasp-session-management.md
- owasp-authorization.md
- owasp-deserialization.md
- owasp-xxe.md
- owasp-cryptographic-storage.md