---
title: "CWE-621: Variable Extraction Error"
url: https://radicalnotion.ai/cwe/cwe-621
type: cwe
description: "The product uses external input to determine the names of variables into which information is extracted, without verifying that the names of the specified variables are valid."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-621: Variable Extraction Error

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

## Description

The product uses external input to determine the names of variables into which information is extracted, without verifying that the names of the specified variables are valid.

## Alternate terms

- Variable overwrite

## Modes of introduction

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

## Applicable platforms

**Languages:** PHP (Undetermined), Interpreted (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity | Modify Application Data | An attacker could cause the program to overwrite unintended variables. |
| Integrity | Modify Application Data | When using PHP, calling extract() or import\_request\_variables() without the proper arguments could allow arbitrary global variables to be overwritten, including superglobals. |

## Potential mitigations

### Implementation (Input Validation)

Use allowlists of variable names that can be extracted.

### Implementation (Refactoring)

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.

## Demonstrative examples

### Example 1

This code uses the credentials sent in a POST request to login a user. It used extract() to provide functionality similar to register\_globals.

Bad code:

```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));
```

The call to extract() will overwrite the existing values of any variables defined previously, in this case $isAdmin. An attacker can send a POST request with an unexpected third value "isAdmin" equal to "true", thus gaining Admin privileges.

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2006-7135 | extract issue enables file inclusion |
| CVE-2006-7079 | Chain: PHP app uses extract for register\_globals compatibility layer (CWE-621), enabling path traversal (CWE-22) |
| CVE-2007-0649 | extract() buried in include files makes post-disclosure analysis confusing; original report had seemed incorrect. |
| CVE-2006-6661 | extract() enables static code injection |
| CVE-2006-2828 | import\_request\_variables() buried in include files makes post-disclosure analysis confusing |

## Real CVEs with this weakness

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2018-6334 | - | critical | 9.8 | - | No | 2018-12-31 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-914](https://radicalnotion.ai/cwe/cwe-914) | Improper Control of Dynamically-Identified Variables |
| Can precede | [CWE-471](https://radicalnotion.ai/cwe/cwe-471) | Modification of Assumed-Immutable Data (MAID) |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| Software Fault Patterns | Tainted input to command | SFP24 | - |

## Frequently asked questions

### What is CWE-621?

The product uses external input to determine the names of variables into which information is extracted, without verifying that the names of the specified variables are valid.

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

1 recorded CVE is attributed to CWE-621: CVE-2018-6334.

### How do you prevent CWE-621?

Use allowlists of variable names that can be extracted.

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

Exploiting CWE-621 can lead to: Modify Application Data.

### Is CWE-621 actively exploited?

1 recorded CVE is caused by CWE-621; it is not currently in CISA's KEV catalog of actively exploited flaws.

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

---

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