In a language where the user can influence the name of a variable at runtime, if the variable names are not controlled, an attacker can read or write to arbitrary variables, or access arbitrary functions.
The resultant vulnerabilities depend on the behavior of the application, both at the crossover point and in any control/data flow that is reachable by the related variables or functions.

Primary

Many interpreted languages support the use of a "$$varname" construct to set a variable whose name is specified by the $varname variable. In PHP, these are referred to as "variable variables." Functions might also be invoked using similar syntax, such as $$funcname(arg1, arg2).

Dynamic evaluation

Implementation

Confidentiality
Integrity
Availability
Modify Application Data
Execute Unauthorized Code or Commands
An attacker could gain unauthorized access to internal program variables and execute arbitrary code.

Implementation
Refactoring
Refactor the code to avoid dynamic variable evaluation whenever possible.

Implementation
Input Validation
Use only allowlists of acceptable variable or function names.

Implementation
For function names, ensure that you are only calling functions that accept the proper number of arguments, to avoid unexpected null arguments.

CVE-2009-0422
Chain: Dynamic variable evaluation allows resultant remote file inclusion and path traversal.
https://www.cve.org/CVERecord?id=CVE-2009-0422

CVE-2007-2431
Chain: dynamic variable evaluation in PHP program used to modify critical, unexpected $_SERVER variable for resultant XSS.
https://www.cve.org/CVERecord?id=CVE-2007-2431

CVE-2006-4904
Chain: dynamic variable evaluation in PHP program used to conduct remote file inclusion.
https://www.cve.org/CVERecord?id=CVE-2006-4904

CVE-2006-4019
Dynamic variable evaluation in mail program allows reading and modifying attachments and preferences of other users.
https://www.cve.org/CVERecord?id=CVE-2006-4019

Allowed
This CWE entry is at the Variant level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.

Under-studied, probably under-reported. Few researchers look for this issue; most public reports are for PHP, although other languages are affected. This issue is likely to grow in PHP as developers begin to implement functionality in place of register_globals.

CWE Content Team
MITRE
2007-05-07
Draft 6
2007-05-07

Eric Dalci
Cigital
2008-07-01
updated Time_of_Introduction

CWE Content Team
MITRE
2008-09-08
updated Applicable_Platforms, Relationships

CWE Content Team
MITRE
2008-10-14
updated Background_Details, Description

CWE Content Team
MITRE
2011-03-29
updated Description

CWE Content Team
MITRE
2011-06-01
updated Common_Consequences

CWE Content Team
MITRE
2012-05-11
updated Common_Consequences, Relationships

CWE Content Team
MITRE
2012-10-30
updated Potential_Mitigations

CWE Content Team
MITRE
2013-02-21
updated Common_Consequences, Observed_Examples, Potential_Mitigations, Relationships, Weakness_Ordinalities

CWE Content Team
MITRE
2014-07-30
updated Relationships

CWE Content Team
MITRE
2017-11-08
updated References

CWE Content Team
MITRE
2020-02-24
updated Relationships

CWE Content Team
MITRE
2020-06-25
updated Potential_Mitigations

CWE Content Team
MITRE
2023-04-27
updated References, Relationships, Type

CWE Content Team
MITRE
2023-06-29
updated Mapping_Notes