Summary
An authorization flaw in the Grav API plugin allows a narrowly scoped API key to bypass a super-administrator requirement on the Twig content allowlist endpoint. If an attacker can use such a key, they may add tokens to the security allowlist, potentially enabling server-side template injection and subsequent code execution when affected content is rendered.
Affected context
The issue occurs in Grav API plugin deployments using the ReportsController endpoint that modifies the Twig content security allowlist. It becomes risky when a least-privilege API key with api.config.write is associated with a super account, while authorization logic checks the account's direct administrative flag without evaluating the key's individual scopes. The allowlist change is persisted in the site's security configuration and can affect later Twig-in-content rendering.
Exploit preconditions
- Attack surface: Authenticated API access to the reports allowlist endpoint
- Required access: A valid API key with
api.config.write, potentially minted for or associated with a super account - Trigger point: Authorization and processing of a request that updates the Twig content allowlist
- Why exploitation is possible: The endpoint uses a direct super-administrator check that does not account for API-key scope restrictions, allowing a narrowly scoped key to reach a privileged configuration operation
- Additional condition: A later application flow must render affected content through Twig for the allowlist expansion to become an SSTI or code-execution sink
Why this happens
The vulnerability results from inconsistent authorization models at the account and credential levels. Although the endpoint requires api.config.write, it then uses isSuperAdmin() rather than an authorization check that evaluates the active API key's scopes. Because the direct administrative flag is consulted without applying the key's restrictions, a credential with limited permissions can cross a privileged authorization boundary. This maps to CWE-862: Missing Authorization, where access to a sensitive operation is not enforced consistently for the requesting principal.
Potential impact
- An attacker could modify the Twig content security allowlist
- The application may accept otherwise restricted Twig constructs in later content rendering
- Server-side template injection could expose application data or secrets
- The application process could potentially execute attacker-controlled code
- Site integrity, availability, and connected systems may be affected
General mitigation guidance
Mitigation generally focuses on enforcing authorization against the complete requesting principal, including credential-specific scope restrictions, before performing configuration changes.
Common defensive patterns include:
- Use a single authorization policy that evaluates both account roles and API-key scopes
- Require explicit, scope-aware permission checks for privileged configuration operations
- Avoid treating an account's super-administrator status as sufficient for every delegated credential
- Apply strict allowlist formats and schema validation to security-sensitive configuration
- Minimize or disable dynamic Twig evaluation in untrusted content where business requirements permit
- Run the application with least privilege and isolate sensitive configuration and execution capabilities
- Record and review changes to security policies and template-related settings
How teams detect issues like this
Organizations can look for this class of issue through:
- Static analysis rules that flag direct role or flag checks following API-key permission checks
- Code review searches for authorization helpers that omit credential scopes
- Tests that compare account-level privileges with delegated-key privileges for the same endpoint
- API audit logging for changes to Twig allowlists and security configuration files
- Policy checks requiring scope-aware authorization for administrative configuration routes
- Monitoring for unexpected Twig rendering behavior, configuration changes, or child processes from the web application
Automated security review tools may help identify inconsistent authorization paths, but endpoint-level tests should verify effective permissions for each credential type.

