COMMON WEAKNESS ENUMERATIONIncomplete

CWE-627

Dynamic Variable Evaluation

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.

Abstraction

Variant

Structure

Simple

Likelihood of Exploit

Medium

Understand the problem

What is the problem?

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.

Extended description

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.

Terminology

Alternate terms and usages

Dynamic evaluation

Root cause

How and when does the problem arise?

Lifecycle phase

Implementation

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

Risk

What does successful exploitation lead to?

Modify Application DataExecute Unauthorized Code or Commands

Affected security scopes: Confidentiality, Integrity, Availability

An attacker could gain unauthorized access to internal program variables and execute arbitrary code.

Defence

How is it prevented and fixed?

Implementation

Refactoring

Detail
Refactor the code to avoid dynamic variable evaluation whenever possible.

Implementation

Input Validation

Detail
Use only allowlists of acceptable variable or function names.

Implementation

Implementation-phase defence

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