Summary
Yii 2.0.54 and earlier contain a Local File Inclusion flaw in the core view rendering method View::renderPhpFile() caused by unsafe extraction of caller-supplied parameters.
By providing a _file_ key in the $params array, an attacker can override the internal variable that determines which PHP file is required, enabling inclusion of unintended files, information disclosure, and potential remote code execution if file-write primitives exist elsewhere.
Affected context
The vulnerability appears in applications built on Yii 2 that use the View::renderPhpFile() method for server-side view rendering.
It becomes relevant when user-controllable data can influence the $params array passed into view rendering, especially if the _file_ key can be set directly or indirectly.
Risk increases in deployments where PHP files can be uploaded or written via another bug or feature (e.g., file uploads stored as executable PHP), and where view rendering is invoked dynamically based on application logic.
Exploit preconditions
- Attack surface: Server-side HTTP endpoints that call Yii view rendering (
View::renderPhpFile()or wrappers) with attacker-influenced$params. - Required access: Ability to supply or affect the
$paramsarray used for view rendering (e.g., via controller actions that pass request data into views). - Trigger point: Execution of
View::renderPhpFile()where the_params_array contains a_file_key controlled by the attacker. - Why exploitation is possible: The function calls
extract($_params_, EXTR_OVERWRITE)before therequirethat loads the view file, allowing_file_in$paramsto overwrite the internal_file_variable that specifies which PHP file is included.
Why this happens
The core issue is unsafe variable extraction combined with file inclusion logic.
View::renderPhpFile() uses extract($_params_, EXTR_OVERWRITE) on user-influenced data and then relies on a local variable (e.g., _file_) to hold the path of the view file to include.
Because EXTR_OVERWRITE allows parameters to overwrite existing local variables, an attacker-controlled _file_ key can replace the intended view path with an arbitrary value.
This pattern maps to:
- CWE-98: Improper Control of Filename for Include/Require Statement, where user input controls which file is executed.
- CWE-20: Improper Input Validation, since the framework does not sufficiently constrain or validate the
_file_parameter or the set of includable paths.
Potential impact
- Local File Inclusion of unintended PHP files accessible to the PHP process.
- Execution of attacker-controlled PHP code if they can upload or write PHP files elsewhere in the application or filesystem.
- Disclosure of sensitive information contained in local PHP or template files that echo or expose secrets when executed.
- Bypass of intended view resolution logic and security assumptions around which templates may be rendered.
- Pivot to broader server compromise if RCE is achieved and the process has high privileges.
General mitigation guidance
Effective mitigation focuses on separating user data from control variables and constraining which files can be included:
- Avoid using
extract()on untrusted arrays in framework core and application code, especially withEXTR_OVERWRITE; prefer explicit variable assignment. - Keep internal control variables (such as the file path to include) isolated from user-controlled parameter bags and do not reuse the same variable names in public APIs.
- Enforce strict whitelisting or mapping of view/template names to file paths, rather than allowing callers to specify arbitrary filesystem locations.
- Normalize and validate any file identifiers against an allowed set or directory, ensuring that user input cannot break out of designated view directories.
- Run PHP with least privileges and restrict write/execute permissions so that even if a path is misused, attackers have fewer options to introduce executable content.
How teams detect issues like this
Detection can be approached through both code-centric and behavior-centric methods:
- Static analysis: Define rules to flag
extract()usage withEXTR_OVERWRITE(or default flags) on arrays that can contain user data, especially in proximity torequire,include,include_once, orrequire_once. - Code review: Look for view rendering code paths where request parameters, query strings, or form data are passed directly into
$paramsarrays without filtering reserved keys like_file_. - Security testing: Implement dynamic tests that attempt to override internal template or file parameters and observe whether unexpected templates or files are rendered.
- Policy enforcement: Establish internal guidelines discouraging the use of
extract()and mandating explicit mapping for file inclusion, and enforce them via linters or pre-commit hooks.

