Skip to main content
Menu
Advisories

Stored XSS in Shortcode Core via unescaped [lorem] tag and [details] summary parameters

GHSA-HVM8-WX3F-J774Published Updated GitHub

Description

Two shortcodes in Shortcode Core wrote an author-supplied parameter into the rendered page without escaping or validating it, allowing a user with ordinary page-edit access to store HTML and JavaScript that executes in the browser of anyone who views the page — including an administrator.

The more serious of the two is [lorem]'s tag parameter. Because a crafted value contains no literal <, it passes Grav's save-time XSS scan (Security::detectXss(), which anchors on a tag opening) and is written into the page as a live element with an event handler attached. This is the same evasion class as GHSA-q5fw-vpqc-fgph, the 6.2.2 attribute-escaping sweep.

The second is [details]'s summary parameter, which was interpolated into <summary>...</summary> unescaped — one line above the class attribute that the 6.2.2 sweep did escape.

Affected versions

  • Package: getgrav/grav-plugin-shortcode-core (Composer)
  • Affected: <= 6.2.4
  • Patched: 6.2.5

The plugin is bundled with the Grav Admin distribution, so most Grav sites have it installed.

Details

[lorem] — tag parameter

classes/shortcodes/LoremShortcode.php read the tag parameter with no validation and passed it to output(), which builds the wrapper element with sprintf('<%1$s>%2$s</%1$s>', $tag, $string). Anything beyond a bare tag name is therefore an injection:

[lorem p=2 tag="img src=x onerror=alert(1) " /]

renders as <img src=x onerror=alert(1) >...</img src=x onerror=alert(1) >, firing without any user interaction. Critically, the stored shortcode holds no literal <, so Grav's save-time content scan never sees it and an ordinary page editor can store it successfully.

[details] — summary parameter

classes/shortcodes/DetailsShortcode.php concatenated the summary parameter directly into the returned markup:

$summary = $sc->getParameter('summary', $this->getBbCode($sc));
$summaryHTML = $summary ? '<summary>' . $summary . '</summary>' : '';
...
$classHTML = (isset($class) and $class !== $summary) ? 'class="' . self::escAttr($class) . '"' : '';
...
return '<details ' . $classHTML . '>' . $summaryHTML . $content . '</details>';

$class was correctly escaped via self::escAttr() (htmlspecialchars, ENT_QUOTES); $summary was not.

Shortcodes are processed by the Thunderer Shortcode library as a text-substitution pass over page content, independent of Twig. Unlike a Twig function or filter, the string a handler returns is the literal HTML that lands in the rendered page — there is no auto-escape step afterward and no render-time scan of shortcode output. Each handler is therefore responsible for encoding the parameter values it concatenates into markup.

Proof of concept

Verified against the vendored Thunderer Shortcode library and the real, unmodified handler closures.

[lorem]:

[lorem p=2 tag="img src=x onerror=alert(1) " /]

Output contains a live <img ... onerror=alert(1)> element. The payload stores successfully as a non-administrator, because it contains no <.

[details], payload 1:

[details summary="</summary><script>alert(document.cookie)</script><summary>x"]Some content[/details]

Output:

<details ><summary></summary><script>alert(document.cookie)</script><summary>x</summary>Some content</details>

[details], payload 2:

[details summary="<img src=x onerror=alert(1)>"]content[/details]

Output:

<details ><summary><img src=x onerror=alert(1)></summary>content</details>

Control — class instead of summary:

[details class="<script>alert(2)</script>"]content[/details]

Output:

<details class="&lt;script&gt;alert(2)&lt;/script&gt;">content</details>

The control confirms that the escaping mechanism and the test harness both work, ruling out a harness artifact and isolating the missing escape to summary.

Impact

Stored cross-site scripting. A user with ordinary page-edit permission — no elevated privileges — can inject arbitrary HTML and JavaScript into a rendered page. The payload executes in the browser of every visitor to that page, including a logged-in administrator or super-admin who opens or previews it, where it can read the admin nonce and act with that session. The <img onerror> variants fire without any click.

Trust boundary: crossed. Page-edit permission grants authoring content; it does not grant executing script inside an administrator's session or an anonymous visitor's browser.

Note that the [details] half alone is substantially mitigated in practice: breaking out of <summary>...</summary> requires a literal <, and Grav's save-time content validator rejects those payloads for any account below super-admin. The [lorem] half carries the severity, since it needs no < and is stored without complaint.

Patches

Fixed in Shortcode Core 6.2.5.

  • [lorem]'s tag parameter is now restricted to a bare tag name (/^[a-z][a-z0-9]*$/i) and falls back to p for anything else.
  • [details]'s summary parameter is now escaped with self::escAttr() when written into the page, matching the adjacent class handling.

Users should upgrade to 6.2.5. There is no configuration workaround; if you cannot upgrade immediately, audit page content for [lorem] shortcodes carrying a tag parameter that is not a plain tag name.

Credits

Reported by @alham-rizvi, who identified both issues and supplied verified proof-of-concept output for each.

Affected versions

References

GitHub · getgrav/grav