Description
The product compares two entities in a security-relevant context, but the comparison is incorrect.
This Pillar covers several possibilities:
Potential Impact
Other
Varies by Context
Demonstrative Examples
public class Truck {
private String make;private String model;private int year;
public boolean equals(Object o) {
if (o == null) return false;if (o == this) return true;if (!(o instanceof Truck)) return false;
Truck t = (Truck) o;
return (this.make.equals(t.getMake()) && this.model.equals(t.getModel()));
}
}/* Ignore CWE-259 (hard-coded password) and CWE-309 (use of password system for authentication) for this example. */
char *username = "admin";char *pass = "password";
int AuthenticateUser(char *inUser, char *inPass) {if (strncmp(username, inUser, strlen(inUser))) {logEvent("Auth failure of username using strlen of inUser");return(AUTH_FAIL);}if (! strncmp(pass, inPass, strlen(inPass))) {logEvent("Auth success of password using strlen of inUser");return(AUTH_SUCCESS);}else {logEvent("Auth fail of password using sizeof");return(AUTH_FAIL);}}
int main (int argc, char **argv) {
int authResult;if (argc < 3) {ExitError("Usage: Provide a username and password");}authResult = AuthenticateUser(argv[1], argv[2]);if (authResult == AUTH_SUCCESS) {DoAuthenticatedTask(argv[1]);}else {ExitError("Authentication failed");}}ppapaspassDetection Methods
- Automated Static Analysis — 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 sea
Real-World CVE Examples
| CVE ID | Description |
|---|---|
| CVE-2021-3116 | Chain: Python-based HTTP Proxy server uses the wrong boolean operators (CWE-480) causing an incorrect comparison (CWE-697) that identifies an authN failure if all three conditions are met instead of |
| CVE-2020-15811 | Chain: Proxy uses a substring search instead of parsing the Transfer-Encoding header (CWE-697), allowing request splitting (CWE-113) and cache poisoning |
| CVE-2016-10003 | Proxy performs incorrect comparison of request headers, leading to infoleak |
Frequently Asked Questions
What is CWE-697?
CWE-697 (Incorrect Comparison) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Pillar-level weakness. The product compares two entities in a security-relevant context, but the comparison is incorrect.
How can CWE-697 be exploited?
Attackers can exploit CWE-697 (Incorrect Comparison) to varies by context. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-697?
Follow secure coding practices, conduct code reviews, and use automated security testing tools (SAST/DAST) to detect this weakness early in the development lifecycle.
What is the severity of CWE-697?
CWE-697 is classified as a Pillar-level weakness (Foundational abstraction). It has been observed in 3 real-world CVEs.