/

CVE-2026-39850

Severity:

HIGH RISK

(7.4)

Local File Inclusion in Yii2 View::renderPhpFile

CVE-2026-39850

Deferred

Vulnerability type

Category:

Local File Inclusion

CWE:

CWE-20, CWE-98

Impact:

Local File Inclusion with potential Remote Code Execution and Information Disclosure

Severity:

HIGH RISK

(7.4)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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 $params array 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 the require that loads the view file, allowing _file_ in $params to 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 with EXTR_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 with EXTR_OVERWRITE (or default flags) on arrays that can contain user data, especially in proximity to require, include, include_once, or require_once.
  • Code review: Look for view rendering code paths where request parameters, query strings, or form data are passed directly into $params arrays 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.

Sources

SourceLink
github.comgithub.com/yiisoft/yii2/commit/109878b491dbffa541032bc99fb5e26d12cd0375
github.comgithub.com/yiisoft/yii2/security/advisories/GHSA-5vpg-rj7q-qpw2

Frequently asked

questions

Yes, it can be remotely exploitable in scenarios where remote users can influence the $params passed to View::renderPhpFile(). If they can set the _file_ key, they may control which file is included and executed.

The attacker needs the ability to supply or influence the view parameters, typically through web routes or controllers that pass request data into view rendering. For full remote code execution, they also need a way to place malicious PHP files on the server via uploads or another vulnerability.

The safest pattern is to eliminate extract() on untrusted data and keep internal control variables (like the file path to include) separate from user-supplied parameters. Use explicit variable assignment and a controlled mapping from logical view names to physical files.

Avoid patterns where user data can overwrite internal variables or control file paths. Enforce strong input validation, use whitelists for includable files, discourage use of extract() in code standards, and incorporate static analysis rules that flag unsafe inclusion and template rendering constructs.

Find out what's already
exploitable in your codebase.