Summary
Grav's Twig sandbox may allow users with page-edit permission to access sensitive system configuration values when configuration access is enabled. By calling configuration helpers from Twig templates, an attacker could retrieve secrets such as a Redis password.
Affected context
The issue occurs in Grav deployments using Twig sandboxing with an incomplete default denylist and configuration access enabled. It becomes risky when a user who can edit pages is also able to influence Twig template content or otherwise cause templates to invoke configuration access methods.
Exploit preconditions
- Attack surface: Twig template rendering in the Grav CMS
- Required access: Permission to edit pages or otherwise control relevant template content
- Trigger point: Rendering a template that invokes configuration access functionality
- Required configuration: Configuration access must be enabled and the affected values must be present
- Why exploitation is possible: The sandbox denylist does not sufficiently restrict access to sensitive system configuration data
Why this happens
The underlying bug is an incomplete access-control policy in the Twig sandbox. Configuration helper methods remain available for retrieving sensitive values even though templates are treated as restricted content. This reflects CWE-522, where credentials or other authentication-related secrets are insufficiently protected from unauthorized disclosure.
Potential impact
- Sensitive configuration values may be disclosed
- Redis or other service credentials could be exposed
- Attackers could use recovered secrets to access connected services
- Application data or session security could be weakened
- Further compromise may occur depending on the privileges of exposed credentials
General mitigation guidance
Mitigation generally focuses on reducing trust in template-authored content
and enforcing a complete, deny-by-default sandbox policy.
Common defensive patterns include:
- Exposing only explicitly approved, non-sensitive template variables and methods
- Preventing Twig templates from reading application-wide configuration objects
- Treating page-edit permissions as potentially security-sensitive
- Keeping credentials outside template-accessible configuration paths
- Applying least privilege and narrow scopes to service credentials
- Requiring explicit authorization before enabling configuration access
- Rotating exposed secrets when unauthorized disclosure is suspected
How teams detect issues like this
Detection approaches may include:
- Static analysis for template calls that access configuration objects or conversion helpers
- Code review checks for sandbox allowlists and default-deny behavior
- Policy tests verifying that templates cannot retrieve credential-bearing settings
- Audit logging for page edits, template changes, and configuration-access events
- Automated security review tools that flag sensitive data flows into rendered templates

