---
title: "CWE-697: Incorrect Comparison"
url: https://radicalnotion.ai/cwe/cwe-697
type: cwe
description: "The product compares two entities in a security-relevant context, but the comparison is incorrect."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-697: Incorrect Comparison

- **Abstraction:** Pillar
- **Structure:** Simple
- **Status:** Incomplete
- **CVEs with this as primary weakness:** 137
- **Of those, in CISA KEV:** 1
- **New in 2026:** 40
- **CWE catalog version:** 4.21

## Description

The product compares two entities in a security-relevant context, but the comparison is incorrect.

This weakness covers several possibilities:

the comparison checks one factor incorrectly;

the comparison should consider multiple factors, but it does not check at least one of those factors at all;

the comparison checks the wrong factor.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Other | Varies by Context | When the comparison is incorrect, it may lead to resultant weaknesses. |

## Detection 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 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.)

## Demonstrative examples

### Example 1

Consider an application in which Truck objects are defined to be the same if they have the same make, the same model, and were manufactured in the same year.

Bad code:

```java
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()));
    }
}
```

Here, the equals() method only checks the make and model of the Truck objects, but the year of manufacture is not included.

### Example 2

This example defines a fixed username and password. The AuthenticateUser() function is intended to accept a username and a password from an untrusted user, and check to ensure that it matches the username and password. If the username and password match, AuthenticateUser() is intended to indicate that authentication succeeded.

Bad code:

```c
/* 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");
    }
}
```

Attack code:

```
p
pa
pas
pass
```

## Observed examples

| CVE | 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 only one, allowing bypass of the proxy authentication (CWE-1390) |
| 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 |

## Real CVEs with this weakness (sample of 12 of 137)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2020-5849 | Unraid Authentication Bypass Vulnerability | critical | 9.3 | - | Yes | 2020-03-16 |
| CVE-2026-33816 | CVE-2026-33816 in github.com/jackc/pgx | critical | 9.8 | - | No | 2026-04-07 |
| CVE-2025-54336 | - | critical | 9.8 | - | No | 2025-08-19 |
| CVE-2024-24621 | Softaculous Webuzo Authentication Bypass | critical | 9.8 | - | No | 2024-07-25 |
| CVE-2023-32571 | Dynamic Linq vulnerable to remote code execution | critical | 9.8 | - | No | 2023-06-22 |
| CVE-2022-47034 | - | critical | 9.8 | - | No | 2023-02-13 |
| CVE-2014-125057 | mrobit robitailletheknot CSRF Token filters.php comparison | critical | 9.8 | - | No | 2023-01-07 |
| CVE-2021-44971 | - | critical | 9.8 | - | No | 2022-01-28 |
| CVE-2021-3833 | Integria IMS incorrect authorization | critical | 9.8 | - | No | 2021-10-07 |
| CVE-2021-35973 | - | critical | 9.8 | - | No | 2021-06-30 |
| CVE-2020-23360 | - | critical | 9.8 | - | No | 2021-01-27 |
| CVE-2020-23359 | - | critical | 9.8 | - | No | 2021-01-27 |

## Related attack patterns (CAPEC)

- [CAPEC-10](https://radicalnotion.ai/capec/capec-10): Buffer Overflow via Environment Variables
- [CAPEC-120](https://radicalnotion.ai/capec/capec-120): Double Encoding
- [CAPEC-14](https://radicalnotion.ai/capec/capec-14): Client-side Injection-induced Buffer Overflow
- [CAPEC-15](https://radicalnotion.ai/capec/capec-15): Command Delimiters
- [CAPEC-182](https://radicalnotion.ai/capec/capec-182): Flash Injection
- [CAPEC-24](https://radicalnotion.ai/capec/capec-24): Filter Failure through Buffer Overflow
- [CAPEC-267](https://radicalnotion.ai/capec/capec-267): Leverage Alternate Encoding
- [CAPEC-3](https://radicalnotion.ai/capec/capec-3): Using Leading 'Ghost' Character Sequences to Bypass Input Filters
- [CAPEC-41](https://radicalnotion.ai/capec/capec-41): Using Meta-characters in E-mail Headers to Inject Malicious Payloads
- [CAPEC-43](https://radicalnotion.ai/capec/capec-43): Exploiting Multiple Input Interpretation Layers
- [CAPEC-44](https://radicalnotion.ai/capec/capec-44): Overflow Binary Resource File
- [CAPEC-45](https://radicalnotion.ai/capec/capec-45): Buffer Overflow via Symbolic Links
- [CAPEC-46](https://radicalnotion.ai/capec/capec-46): Overflow Variables and Tags
- [CAPEC-47](https://radicalnotion.ai/capec/capec-47): Buffer Overflow via Parameter Expansion
- [CAPEC-52](https://radicalnotion.ai/capec/capec-52): Embedding NULL Bytes
- [CAPEC-53](https://radicalnotion.ai/capec/capec-53): Postfix, Null Terminate, and Backslash
- [CAPEC-6](https://radicalnotion.ai/capec/capec-6): Argument Injection
- [CAPEC-64](https://radicalnotion.ai/capec/capec-64): Using Slashes and URL Encoding Combined to Bypass Validation Logic
- [CAPEC-67](https://radicalnotion.ai/capec/capec-67): String Format Overflow in syslog()
- [CAPEC-7](https://radicalnotion.ai/capec/capec-7): Blind SQL Injection
- [CAPEC-71](https://radicalnotion.ai/capec/capec-71): Using Unicode Encoding to Bypass Validation Logic
- [CAPEC-73](https://radicalnotion.ai/capec/capec-73): User-Controlled Filename
- [CAPEC-78](https://radicalnotion.ai/capec/capec-78): Using Escaped Slashes in Alternate Encoding
- [CAPEC-79](https://radicalnotion.ai/capec/capec-79): Using Slashes in Alternate Encoding
- [CAPEC-8](https://radicalnotion.ai/capec/capec-8): Buffer Overflow in an API Call
- [CAPEC-80](https://radicalnotion.ai/capec/capec-80): Using UTF-8 Encoding to Bypass Validation Logic
- [CAPEC-88](https://radicalnotion.ai/capec/capec-88): OS Command Injection
- [CAPEC-9](https://radicalnotion.ai/capec/capec-9): Buffer Overflow in Local Command-Line Utilities
- [CAPEC-92](https://radicalnotion.ai/capec/capec-92): Forced Integer Overflow

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Child | [CWE-183](https://radicalnotion.ai/cwe/cwe-183) | Permissive List of Allowed Inputs |
| Child | [CWE-185](https://radicalnotion.ai/cwe/cwe-185) | Incorrect Regular Expression |
| Child | [CWE-581](https://radicalnotion.ai/cwe/cwe-581) | Object Model Violation: Just One of Equals and Hashcode Defined |
| Child | [CWE-1023](https://radicalnotion.ai/cwe/cwe-1023) | Incomplete Comparison with Missing Factors |
| Child | [CWE-1024](https://radicalnotion.ai/cwe/cwe-1024) | Comparison of Incompatible Types |
| Child | [CWE-1025](https://radicalnotion.ai/cwe/cwe-1025) | Comparison Using Wrong Factors |
| Child | [CWE-1039](https://radicalnotion.ai/cwe/cwe-1039) | Inadequate Detection or Handling of Adversarial Input Perturbations in Automated Recognition Mechanism |
| Child | [CWE-1077](https://radicalnotion.ai/cwe/cwe-1077) | Floating Point Comparison with Incorrect Operator |
| Child | [CWE-1254](https://radicalnotion.ai/cwe/cwe-1254) | Incorrect Comparison Logic Granularity |
| Related | [CWE-481](https://radicalnotion.ai/cwe/cwe-481) | Assigning instead of Comparing |

## Frequently asked questions

### What is CWE-697?

The product compares two entities in a security-relevant context, but the comparison is incorrect.

### What CVEs are caused by CWE-697?

137 recorded CVEs are attributed to CWE-697, including CVE-2020-5849, CVE-2026-33816 and CVE-2025-54336. 1 is listed in CISA's Known Exploited Vulnerabilities (KEV) catalog.

### How is CWE-697 detected?

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 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.)

### What are the consequences of CWE-697?

Exploiting CWE-697 can lead to: Varies by Context.

### Is CWE-697 actively exploited?

Yes. 1 CWE-697 vulnerability is in CISA's KEV catalog of actively exploited flaws, out of 137 recorded CVEs.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/697.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-697). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
