Expression is Always True

Draft Base
Structure: Simple
Description

This vulnerability occurs when code contains a conditional expression that will always evaluate to 'true', making the check ineffective and potentially bypassing critical security or logic gates.

Extended Description

An 'always true' expression often stems from logic errors where a developer compares a variable against itself, uses a constant instead of a variable, or creates a condition that can never be false due to prior operations. For example, checking `if (x > 5 || x >= 5)` is redundant because the second part is always true if the first is false. This dead code not only clutters the logic but can silently disable security validations, access controls, or error-handling routines, creating a false sense of security. From a security perspective, these flaws are particularly dangerous in authentication checks, input validation, or privilege escalation guards, as they may allow unauthorized actions to proceed. To prevent this, developers should audit conditional logic for tautologies, use static analysis tools to detect unreachable code, and carefully review comparisons involving constants or variables that may have been modified earlier in the function flow.

Common Consequences 1
Scope: Other

Impact: Quality DegradationVaries by Context

Detection Methods 1
Automated Static AnalysisHigh
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
Potential Mitigations 1
Phase: Testing
Use Static Analysis tools to spot such conditions.
Demonstrative Examples 1
In the following Java example the updateInventory() method used within an e-business product ordering/inventory application will check if the input product number is in the store or in the warehouse. If the product is found, the method will update the store or warehouse database as well as the aggregate product database. If the product is not found, the method intends to do some special processing without updating any database.

Code Example:

Bad
Java
java

/* Warn customer about delay before order processing / ...}}

However, the method never sets the isDelayed variable and instead will always update the isProductAvailable variable to true. The result is that the predicate testing the isProductAvailable boolean will always evaluate to true and therefore always update the product database. Further, since the isDelayed variable is initialized to false and never changed, the expression always evaluates to false and the customer will never be warned of a delay on their product.
Applicable Platforms
Languages:
Not Language-Specific : Undetermined
Modes of Introduction
Implementation
Taxonomy Mapping
  • CERT C Secure Coding
  • Software Fault Patterns