CWE-621 Variant Incomplete

Variable Extraction Error

This vulnerability occurs when an application uses unvalidated external input to dynamically select which variables to populate with data. Without proper checks, this can allow an attacker to…

Definition

What is CWE-621?

This vulnerability occurs when an application uses unvalidated external input to dynamically select which variables to populate with data. Without proper checks, this can allow an attacker to overwrite critical internal variables, leading to unexpected behavior or security breaches.
In languages like PHP, functions such as `extract()` or `import_request_variables()` can mimic the dangerous behavior of the deprecated `register_globals` feature if called incorrectly. An attacker can manipulate input to overwrite global variables, including superglobals like `$_SESSION` or `$_GET`, potentially bypassing security controls or altering application logic. This pattern is not exclusive to PHP. Many interpreted languages and custom frameworks offer similar dynamic variable assignment features. Developers must always validate or whitelist which variable names are allowed to be set externally, treating user input as data, not as code that defines the program's structure.
Auswirkungen in der Praxis

Real-world CVEs caused by CWE-621

  • extract issue enables file inclusion

  • Chain: PHP app uses extract for register_globals compatibility layer (CWE-621), enabling path traversal (CWE-22)

  • extract() buried in include files makes post-disclosure analysis confusing; original report had seemed incorrect.

  • extract() enables static code injection

  • import_request_variables() buried in include files makes post-disclosure analysis confusing

Wie Angreifer es ausnutzen

Angreiferpfad Schritt für Schritt

  1. 1

    Identifiziere einen Codepfad, der nicht vertrauenswürdige Eingaben ohne Validierung verarbeitet.

  2. 2

    Erzeuge eine Payload, die das unsichere Verhalten auslöst — Injection, Traversal, Overflow oder Logik-Missbrauch.

  3. 3

    Liefere die Payload über einen normalen Request aus und beobachte die Reaktion der Anwendung.

  4. 4

    Iteriere, bis die Antwort Daten preisgibt, Angreifer-Code ausführt oder Berechtigungen eskaliert.

Verwundbares Codebeispiel

Vulnerable PHP

This code uses the credentials sent in a POST request to login a user.

Verwundbar PHP
```
//Log user in, and set $isAdmin to true if user is an administrator* 
  
  function login($user,$pass){
  ```
  	$query = buildQuery($user,$pass);
  	mysql_query($query);
  	if(getUserRole($user) == "Admin"){
  		$isAdmin = true;
  	}
  }
  $isAdmin = false;
  extract($_POST);
  login(mysql_real_escape_string($user),mysql_real_escape_string($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-621

  • Implementation Use allowlists of variable names that can be extracted.
  • Implementation Consider refactoring your code to avoid extraction routines altogether.
  • Implementation In PHP, call extract() with options such as EXTR_SKIP and EXTR_PREFIX_ALL; call import_request_variables() with a prefix argument. Note that these capabilities are not present in all PHP versions.
Erkennungssignale

How to detect CWE-621

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-621 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-621?

This vulnerability occurs when an application uses unvalidated external input to dynamically select which variables to populate with data. Without proper checks, this can allow an attacker to overwrite critical internal variables, leading to unexpected behavior or security breaches.

Wie gravierend ist CWE-621?

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-621 betroffen?

MITRE lists the following affected platforms: PHP.

Wie kann ich CWE-621 verhindern?

Use allowlists of variable names that can be extracted. Consider refactoring your code to avoid extraction routines altogether.

Wie erkennt und behebt Plexicus CWE-621?

Die SAST-Engine von Plexicus erkennt die Datenfluss-Signatur von CWE-621 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-621?

MITRE veröffentlicht die kanonische Definition unter https://cwe.mitre.org/data/definitions/621.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.