Details
Step 4, run it:
$ php twig_sandbox_poc.php
Actual output:
Template : {{ system.cache.redis.password }}
Rendered output : REDACTED-REAL-SECRET-VALUE-abc123
Sandbox blocked it : NO, the secret was rendered in plain text
For reference, running the same script before I added escape to the allowed filters (autoescape is forced on, so every {{ }} in real Grav goes through the escape filter first) correctly failed closed:
Sandbox threw a SecurityError (blocked): Filter "escape" is not allowed in "page_content" at line 1.
which confirms the harness is actually exercising the sandbox's enforcement path, not silently skipping it, and that the only reason system.cache.redis.password got through is the array access itself, not a policy misconfiguration in my test.
This demonstrates the mechanism precisely: no matter how the allowed_classes/allowed_methods/allowed_properties lists in system/config/security.yaml are configured, and independent of config_denied_paths entirely, a raw array handed to the sandboxed template is fully readable. Combined with the direct source reading in the "Affected code" section above, showing that system, site, and theme are exactly such raw arrays and are carried unfiltered into processPage()'s sandboxed render, this is a complete, verified chain from source to impact. I was not able to additionally capture a live HTTP round trip against a running Grav install with real page content, for the same reason as my other reports, no bootstrapped instance available in this sandbox, but every step of the actual code path has been verified against the real source, not reconstructed or assumed.
Impact
Any content author who can enable Twig processing on a page (process.twig: true in page frontmatter, gated by security.twig_content.process_enabled, or unconditionally for modular page content per the comment in processPage()) can read the entire system, site, and theme configuration trees, including any secret that happens to live there, such as system.cache.redis.password in core, and whatever plugins may nest under site.* for their own settings, since plugin config lives elsewhere (plugins.*) but site owners commonly stash site-specific integration keys under site.* custom fields. This works regardless of twig_content.config_access, which was presumably assumed to be the single gate for config exposure in sandboxed content, it is not, system/site/theme were never part of that gate.
Suggested fix
The config_denied_paths fix pattern (a filtering facade) does not apply here since these are plain arrays, not an object with its own get(). The direct fix is to stop injecting the raw arrays into the sandboxed render, options in rough order of how much they preserve existing template behavior:
- In
processPage(), after copying$sandbox_vars = $twig_vars;, also strip or replacesystem,site, andthemefor that specific sandboxed call, the same wayconfigalready gets replaced. ASandboxConfig-style facade wrapping$config->get('system')with its own denied-path list would let you keep the currently-useful subset (e.g.system.pages.*for things page authors are expected to read) while still hiding secrets. - Alternatively, since
configalready gives filtered access to the same data (config.get('system.cache.driver')etc. throughSandboxConfig), consider whethersystem/site/themeneed to be separate top level variables in the sandboxed render at all, versus just being reachable via the already-filteredconfigfacade.
===========================================================
CWE FIELD
===========================================================
CWE-200, Exposure of Sensitive Information to an Unauthorized Actor (secondary: CWE-668, Exposure of Resource to Wrong Sphere, describing the sandbox-bypass mechanism itself)
===========================================================
CVSS CALCULATOR SELECTIONS (v3.1)
===========================================================
Attack Vector: Network
Attack Complexity: Low
Privileges Required: Low
User Interaction: None
Scope: Unchanged
Confidentiality: High
Integrity: None
Availability: None
Resulting vector: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N
Resulting score: 6.5, severity Medium
Note for the maintainer: Privileges Required is set to Low because reaching this requires page-content edit access, which is exactly the privilege level the entire content sandbox exists to constrain, someone with edit rights but who should not have operator-level secrets. If your threat model treats page-content editors as fully trusted, please rescore. I set Confidentiality to High rather than Low because the exposed tree can contain live credentials (a cache backend password, and whatever else operators or plugins choose to nest under system/site), not just configuration shape.
===========================================================
SEVERITY FIELD
===========================================================
Moderate