Summary
Grav's Twig sandbox configuration allows users with the admin.pages role to call config.toArray() from within page content, exposing the full merged site configuration.
When abused, this behavior can leak sensitive plugin secrets such as SMTP passwords, AWS keys, OAuth client secrets, and API tokens directly into rendered HTML, without requiring full administrator privileges.
Affected context
This vulnerability arises in Grav instances where:
- The Twig templating sandbox is enabled and accessible from editable page content
- Users with the
admin.pagesrole are allowed to create or modify page bodies - The configuration object (
config) is exposed to Twig and itstoArray()method is present on the sandbox allow-list
In such environments, page authors with limited administrative capabilities can indirectly access and render merged site configuration values, including secrets normally intended to remain server-side.
Exploit preconditions
- Attack surface: Web-based page editing and rendering in Grav.
- Required access: An authenticated account with the
admin.pagesrole (but not full administrator access). - Trigger point: Insertion of Twig markup into page content that invokes
config.toArray()(or equivalent access path) and subsequent rendering of that page. - Why exploitation is possible: The Twig sandbox allow-list is overly permissive, exposing a powerful configuration object method to untrusted template contexts. The method returns the entire merged configuration without filtering out secret values, and the templating layer renders this data into HTML where it can be viewed or further exfiltrated.
Why this happens
At its core, this is an information exposure issue caused by improper isolation between trusted configuration APIs and untrusted template code.
The Twig sandbox is supposed to restrict what methods and objects can be accessed from user-controlled templates. By placing config.toArray() on the allow-list, the implementation unintentionally granted low-privileged users the ability to enumerate the full configuration tree. Because the configuration structure includes sensitive secrets (credentials, keys, tokens) alongside non-sensitive settings, there is no separation of confidential data from general configuration.
This maps to CWE-200: Exposure of Sensitive Information to an Unauthorized Actor: a server-side API exposing sensitive configuration is directly callable from a context controlled by users who are not authorized to access those secrets, and the system does not enforce any additional filtering or redaction when serializing configuration into templates.
Potential impact
- Disclosure of SMTP credentials, allowing attackers to impersonate the site via outbound email.
- Exposure of cloud provider keys (for example, AWS keys), which could enable access to storage buckets or other cloud resources.
- Leakage of OAuth client secrets and API tokens, potentially permitting account takeover or unauthorized API access.
- Mapping of the full application configuration, assisting in further exploitation, privilege escalation, or lateral movement.
- Compromise of third-party integrations and services that trust Grav to keep shared secrets confidential.
General mitigation guidance
Effective mitigation centers on reducing what configuration and methods are exposed to untrusted template contexts and separating secrets from general configuration.
Pattern-based guidance includes:
- Restrict template sandbox allow-lists: Remove powerful configuration objects and methods (such as
config.toArray()) from templating sandboxes accessible to non-administrative users. Favor narrowly scoped helper functions that return only the specific, non-sensitive values needed for rendering. - Segregate secrets from runtime-readable configuration: Store credentials and tokens in dedicated secret stores or separate configuration domains that are never passed through to template engines. Introduce clear boundaries between content-facing settings and backend-only secrets.
- Redact sensitive fields by default: When configuration is serialized or exposed for debugging or templating, apply filters that automatically redact values matching secret-like patterns (passwords, keys, tokens) or belonging to designated sensitive keys.
- Minimize privileges for content authors: Ensure roles such as
admin.pagesonly have access to content editing and safe template features, not to generic configuration APIs or debugging helpers. - Use explicit data models for templates: Instead of exposing broad configuration objects, define explicit view models or context objects containing only the fields required to render the page.
How teams detect issues like this
Organizations can detect similar issues by reviewing both configuration exposure patterns and template sandbox rules:
- Static analysis of template contexts: Scan server-side code for cases where global configuration objects are injected directly into template contexts or where high-privilege methods are added to template allow-lists.
- Policy-based review of Twig/templating configuration: Maintain a security review checklist for template sandbox configurations, flagging any helpers that expose configuration trees, environment variables, or debugging introspection.
- Source code review of role-based access boundaries: During code review, verify that roles like content editors cannot indirectly reach configuration APIs through templating constructs or plugin-provided functions.
- Automated configuration exposure tests: Implement security tests that render pages under low-privilege roles and inspect the HTML output for sensitive patterns (for example, known key prefixes, email credentials, or token-like strings).
- Use of automated SAST/linters: Employ static analysis tools or custom rules to detect direct exposure of secrets to view layers, such as calls that serialize configuration into templates or logs.

