CakePHP TwigView file reads turn template paths into a data-exfiltration route
CakePHP TwigView file reads turn template paths into a data-exfiltration route CakePHP's TwigView integration could resolve a user-controlled template path outside the intended template directory. The issue affects the
CakePHP TwigView file reads turn template paths into a data-exfiltration route
CakePHP's TwigView integration could resolve a user-controlled template path outside the intended template directory. The issue affects the FileLoader::findTemplate() path when an application passes unvalidated input into Twig's include or extends tags.
The vulnerability is CVE-2026-59191. Versions before 1.3.3 are affected, and the 2.0 branch is affected through 2.1.1. The patched releases are 1.3.3 and 2.1.2. GitHub rates the advisory Moderate with a CVSS score of 5.3.
The direct impact is file disclosure. The attacker does not need a separate upload primitive or code execution. If the application can be induced to compile or display a template from an arbitrary file, the file contents may appear in the rendered output or an error. That can expose configuration, credentials, source code, private keys or customer data.
Why a template path is a security boundary
Template engines are designed to load files. The loader resolves names through its template root, then reads the file. A missing canonical path check lets .. segments or an absolute path move outside that root.
The advisory's workaround is direct: do not supply user-controlled data to include or extends. That is necessary at the application layer because TwigView cannot know which names the application considers authorized.
Applications should map caller input to a small set of server-owned template names. Do not concatenate user input into a path and then pass the result to Twig. If a multi-tenant product needs per-tenant templates, store them under a tenant-specific root, resolve the real path, and verify that it remains beneath that root after normalization and symlink resolution.
Upgrade and inventory
Upgrade to 1.3.3, 2.1.2 or later. Search templates and controllers for include, extends, dynamic template variables, CMS-edited templates and theme names accepted from query parameters. Include indirect paths where a database value supplies the template name. A database field is still user-controlled if a lower-privileged role can edit it.
Run the service with filesystem permissions that expose only the template root and explicitly required runtime files. The web user should not be able to read /etc/shadow, cloud credential files or unrelated application secrets. Least privilege does not prevent the bug, but it changes what a successful read can disclose.
Review web and application logs for template errors involving ../, absolute paths, repeated dot segments or unusual file extensions. Compare those requests with access to sensitive endpoints. If the application returned file content, preserve the response where policy allows and identify the exact file before rotating secrets.
Testing the boundary
Create a test fixture with a file outside the template root and a route that accepts a template name. Submit relative traversal, encoded traversal and absolute-path variants. The expected result is a rejected template, not a rendered file. Test symlinks as well, because a path that starts inside the root can resolve outside it.
The fix should validate the resolved path at the loader boundary and keep application mapping in place. Either control alone is useful. Together they reduce the chance that a future template feature turns another user-controlled label into a local file read.
References
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.