This weakness occurs when a security-critical decision relies on a flawed comparison between two pieces of data. The incorrect logic can create a gap that attackers exploit to bypass checks or trigger unintended behavior.
Incorrect comparisons often happen because the check is too simplistic for the security context. For example, a developer might validate only one attribute when multiple factors should be considered, compare the wrong values entirely, or implement the comparison logic incorrectly (like using the wrong operator). This creates a mismatch between the intended security rule and what the code actually enforces. From a developer's perspective, this flaw is a logic bug in a security gate. It's not about missing a check, but about writing a check that doesn't work as intended. To prevent it, carefully review any comparison used for authentication, authorization, input validation, or state change decisions. Ensure it evaluates all necessary conditions with precise logic and test it with both valid and malicious edge cases.
Impact: Varies by Context
java/* Ignore CWE-259 (hard-coded password) and CWE-309 (use of password system for authentication) for this example. /
c
bash