---
title: "CWE-187: Partial String Comparison"
url: https://radicalnotion.ai/cwe/cwe-187
type: cwe
description: "The product performs a string comparison that only examines a portion of the string before determining whether there is a match."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-187: Partial String Comparison

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Incomplete
- **CVEs with this as primary weakness:** 21
- **Of those, in CISA KEV:** 0
- **New in 2026:** 15
- **CWE catalog version:** 4.21

## Description

The product performs a string comparison that only examines a portion of the string before determining whether there is a match.

## Modes of introduction

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

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity, Access Control | Alter Execution Logic, Bypass Protection Mechanism | An attacker might succeed in authentication by providing a small password that matches the associated portion of the larger, correct password. |

## Potential mitigations

### Testing

Thoroughly test the comparison scheme before deploying code into production. Perform positive testing as well as negative testing.

## Demonstrative examples

### Example 1

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-2014-6394 | Product does not prevent access to restricted directories due to partial string comparison with a public directory |
| CVE-2004-1012 | Argument parser of an IMAP server treats a partial command "body\[p" as if it is "body.peek", leading to index error and out-of-bounds corruption. |
| CVE-2004-0765 | Web browser only checks the hostname portion of a certificate when the hostname portion of the URI is not a fully qualified domain name (FQDN), which allows remote attackers to spoof trusted certificates. |
| CVE-2002-1374 | One-character password by attacker checks only against first character of real password. |
| CVE-2000-0979 | The password is not properly checked, which allows remote attackers to bypass access controls by sending a 1-character password that matches the first character of the real password. |

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

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-115646 | Partial String Comparison Vulnerability in HiRDB | critical | 9.8 | - | No | 2026-11-10 |
| CVE-2024-39742 | IBM MQ Container authentication bypass | critical | 9.8 | - | No | 2024-07-08 |
| CVE-2022-31802 | Partial string comparison in CODESYS gateway server | critical | 9.8 | - | No | 2022-06-24 |
| CVE-2024-41110 | Moby authz zero length regression | critical | 9.4 | - | No | 2024-07-24 |
| CVE-2025-12977 | CVE-2025-12977 | critical | 9.1 | - | No | 2025-11-24 |
| CVE-2026-112266 | SGLang through 0.5.22 Cross-Request Abort via rid Prefix Matching | high | 8.2 | - | No | 2026-10-19 |
| CVE-2026-87853 | Sssd: sssd: idp authentication prefix comparison allows cross-user impersonation | high | 7.5 | - | No | 2026-09-09 |
| CVE-2026-44837 | view\_component: System Test Entry Point Path Check Allows Sibling Directory Escape | high | 7.5 | - | No | 2026-05-26 |
| CVE-2026-34785 | Rack: Local file inclusion in \`Rack::Static\` via URL Prefix Matching | high | 7.5 | - | No | 2026-04-02 |
| CVE-2026-136453 | browser-use before 1.0.0 Allowlist Bypass via \_is\_url\_match | high | 7.1 | - | No | 2026-11-24 |
| CVE-2026-14687 | 666ghj BettaFish InsightEngine search-result Deduplication agent.py \_deduplicate\_results partial string comparison | medium | 6.9 | - | No | 2026-07-05 |
| CVE-2026-101914 | @grpc/grpc-js: The exact path match matcher incorrectly only applies a prefix match for case-insensitive matches | medium | 6.5 | - | No | 2026-09-28 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-1023](https://radicalnotion.ai/cwe/cwe-1023) | Incomplete Comparison with Missing Factors |
| Peer | [CWE-625](https://radicalnotion.ai/cwe/cwe-625) | Permissive Regular Expression |
| Related | [CWE-185](https://radicalnotion.ai/cwe/cwe-185) | Incorrect Regular Expression |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| PLOVER | Partial Comparison | - | - |

## Frequently asked questions

### What is CWE-187?

The product performs a string comparison that only examines a portion of the string before determining whether there is a match.

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

21 recorded CVEs are attributed to CWE-187, including CVE-2026-115646, CVE-2024-39742 and CVE-2022-31802.

### How do you prevent CWE-187?

Thoroughly test the comparison scheme before deploying code into production. Perform positive testing as well as negative testing.

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

Exploiting CWE-187 can lead to: Alter Execution Logic, Bypass Protection Mechanism.

### Is CWE-187 actively exploited?

21 recorded CVEs are caused by CWE-187; none are currently in CISA's KEV catalog of actively exploited flaws.

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

---

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