Summary
A Twig sandbox bypass in Grav can let publishers access sensitive server files by misusing allowlisted functions and page accessor setters during rendering. Exposed private keys or API signing secrets could be used to forge a super-admin API token.
Affected context
The issue affects Grav deployments where publisher-controlled content is rendered through the Twig sandbox and the sandbox exposes the relevant allowlisted function and page accessors. In that context, page objects or asset collections may be manipulated to expose files and secrets that should not be available to publishers.
Exploit preconditions
- Attack surface: Twig-rendered content in a Grav deployment
- Required access: Publisher-level ability to influence content that is rendered
- Trigger point: Rendering content that can access the affected functions and page setters
- Why exploitation is possible: The sandbox's allowed operations can be combined to redirect page or asset references to sensitive files and expose their contents
Why this happens
The sandbox permits a combination of allowlisted function access and page accessor setters that can be used beyond their intended boundaries. This weakens the separation between publisher-controlled templates and server-side files, resulting in exposure of confidential data. The described impact maps to CWE-200: Exposure of Sensitive Information to an Unauthorized Actor.
Potential impact
- Publishers may be able to read private keys or other sensitive server files.
- API signing secrets could be exposed.
- An attacker could potentially forge a super-admin API token using a disclosed signing secret.
- Unauthorized administrative access or further compromise may result.
General mitigation guidance
Mitigation patterns include narrowing the sandbox to a minimal, explicit set of safe operations and avoiding accessors or helpers that can redirect references to server resources. Treat publisher-authored content as untrusted, constrain file access to intended locations, and keep signing secrets outside content-rendering contexts. Apply least privilege to the runtime and limit the authority of credentials available to it.
How teams detect issues like this
Review sandbox configuration and template-facing APIs for allowlisted functions or setters that can affect file paths, page objects, or asset collections. Static analysis and code review can flag broad helper exposure, mutable resource references, and file access reachable from untrusted templates. Policy checks can require explicit sandbox allowlists and prevent secrets from being placed in render-accessible paths; automated review tools may help identify risky patterns.

