CWE-187 Variant Incomplete

Partial String Comparison

This weakness occurs when software checks only part of a string or token to determine a match, instead of comparing the entire value. This incomplete validation can lead to incorrect security…

Definition

What is CWE-187?

This weakness occurs when software checks only part of a string or token to determine a match, instead of comparing the entire value. This incomplete validation can lead to incorrect security decisions.
Partial string comparison happens when a system, such as an authentication module, validates only the first few characters of an input against a stored value. For example, if a password check only verifies the initial 5 characters, an attacker could gain access by providing any password that starts with those same 5 characters, regardless of the full correct password. This flaw fundamentally undermines security logic by treating partially matching inputs as fully authorized. Developers should always enforce complete, exact-string comparisons for security-critical operations like authentication, authorization tokens, or integrity checks to prevent attackers from exploiting these predictable shortcuts.
Auswirkungen in der Praxis

Real-world CVEs caused by CWE-187

  • Product does not prevent access to restricted directories due to partial string comparison with a public directory

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

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

  • One-character password by attacker checks only against first character of real password.

  • One-character password by attacker checks only against first character of real password.

Wie Angreifer es ausnutzen

Angreiferpfad Schritt für Schritt

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

  2. 2

    In AuthenticateUser(), the strncmp() call uses the string length of an attacker-provided inPass parameter in order to determine how many characters to check in the password. So, if the attacker only provides a password of length 1, the check will only examine the first byte of the application's password before determining success.

  3. 3

    As a result, this partial comparison leads to improper authentication (CWE-287).

  4. 4

    Any of these passwords would still cause authentication to succeed for the "admin" user:

  5. 5

    This significantly reduces the search space for an attacker, making brute force attacks more feasible.

Verwundbares Codebeispiel

Vulnerable C

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.

Verwundbar 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");
  		}
  }
Angreifer-Payload

Any of these passwords would still cause authentication to succeed for the "admin" user:

Angreifer-Payload
p
  pa
  pas
  pass
Sicheres Codebeispiel

Secure pseudo

Sicher pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
  const safe = validateAndEscape(input);
  return executeWithGuards(safe);
}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Präventions-Checkliste

How to prevent CWE-187

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

How to detect CWE-187

SAST High

Führe statische Analyse (SAST) auf der Codebasis aus und suche im Datenfluss nach dem unsicheren Muster.

DAST Moderate

Führe dynamische Application-Security-Tests gegen den Live-Endpoint aus.

Runtime Moderate

Beobachte Runtime-Logs auf ungewöhnliche Exception-Traces, fehlerhafte Eingaben oder Versuche, Autorisierung zu umgehen.

Code review Moderate

Code Review: Markiere jeden neuen Code, der Eingaben von dieser Oberfläche ohne validierte Framework-Helper verarbeitet.

Plexicus Auto-Fix

Plexicus erkennt CWE-187 automatisch und öffnet in unter 60 Sekunden einen Fix-PR.

Codex Remedium scannt jeden Commit, identifiziert genau diese Schwachstelle und liefert einen reviewer-ready Pull Request mit dem Patch. Keine Tickets. Keine Hand-offs.

Häufig gestellte Fragen

Frequently asked questions

Was ist CWE-187?

This weakness occurs when software checks only part of a string or token to determine a match, instead of comparing the entire value. This incomplete validation can lead to incorrect security decisions.

Wie gravierend ist CWE-187?

MITRE hat für diese Schwachstelle keine Exploit-Wahrscheinlichkeit veröffentlicht. Behandle sie als mittlere Auswirkung, bis dein Threat Model anderes belegt.

Welche Sprachen oder Plattformen sind von CWE-187 betroffen?

MITRE hat für diese CWE keine betroffenen Plattformen spezifiziert — sie kann in den meisten Anwendungs-Stacks auftreten.

Wie kann ich CWE-187 verhindern?

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

Wie erkennt und behebt Plexicus CWE-187?

Die SAST-Engine von Plexicus erkennt die Datenfluss-Signatur von CWE-187 bei jedem Commit. Bei einem Treffer öffnet unser Codex-Remedium-Agent einen Fix-PR mit korrigiertem Code, Tests und einer einzeiligen Zusammenfassung für den Reviewer.

Wo erfahre ich mehr über CWE-187?

MITRE veröffentlicht die kanonische Definition unter https://cwe.mitre.org/data/definitions/187.html. Für ergänzende Hinweise kannst du auch die OWASP- und NIST-Dokumentation heranziehen.

Bereit, wenn du es bist

Schluss mit dem Bezahlen pro Entwickler.
Schließ den Kreislauf.

Plexicus ist die KI-native ASPM, die scannt, filtert, fixt, pentestet und erklärt — autonom. Unbegrenzte Entwickler, unbegrenzte Repos, Fair-Use-KI-Aktionen. Echter kostenloser Tarif, €269/mo jährlich, wenn du bereit bist.