Skip to main content
Menu
Advisories

getgrav/grav-plugin-admin2 cross-site scripting (XSS)

GHSA-752R-88J4-VXM3Published Updated GitHub

Description

MarkdownEditor.svelte (the live preview pane in the page content editor) and MarkdownModal.svelte (a reusable modal used to show plugin/theme changelogs and update notes) both call marked.parse() on markdown text and inject the result directly into the DOM via Svelte's {@html} directive, with no sanitization step (no DOMPurify, no custom safe renderer) in between. marked does not sanitize dangerous URI schemes in links by default, and hasn't since its sanitize option was removed years ago, the maintainers explicitly document that callers are expected to sanitize output themselves if it's ever attacker-influenced. Neither component does.

{@html} is Svelte's direct equivalent of React's dangerouslySetInnerHTML, it inserts the given string as raw HTML with no escaping.

Affected product and version

Product: Grav Admin2 frontend, getgrav/grav-admin-next Confirmed present in: current develop checkout at time of review, commit c2133c3f9def8a1c86e49fe3a4777d3b9cea8549 marked version pinned in package.json: ^17.0.5

Affected code

src/lib/components/editors/MarkdownEditor.svelte:

const previewHtml = $derived(showPreview ? marked.parse(resolveImagePaths(value || ''), { async: false }) as string : '');
...
{@html previewHtml}

value is the raw markdown text currently in the editor, i.e. exactly what the user (or, given the product's real-time collaborative editing feature, a co-editing collaborator) has typed.

src/lib/components/ui/MarkdownModal.svelte:

const html = $derived(content ? marked.parse(content, { async: false }) as string : '');
...
{@html html}

content is a generic prop, this is a reusable component. Its real callers:

src/routes/plugins/[slug]/+page.svelte   — plugin changelog (modalContent, loaded from the GPM package listing)
src/routes/themes/[slug]/+page.svelte    — theme changelog, same pattern
src/routes/plugins/+page.svelte
src/routes/themes/+page.svelte
src/lib/components/GravUpdateBanner.svelte

On the plugin detail page specifically:

<MarkdownModal
    ...
    content={modalLoading ? 'Loading...' : modalContent}

labeled via i18n.t('ADMIN_NEXT.PLUGINS.CHANGELOG'), confirming this renders a plugin's changelog content.

Proof of concept, verified, real output

I installed the exact pinned marked version and ran it against the same payload class I used against Grav's PHP-side markdown renderer, to confirm the client-side library behaves the same unsafe way with the exact configuration these two components actually use (no options object beyond { async: false }, no sanitizer):

$ npm install marked@17.0.5
$ node test.mjs
import { marked } from 'marked';

const payloads = [
    '[click me](javascript:alert(document.cookie))',
    '[click me](JaVaScRiPt:alert(1))',
    '[legit](https://example.com)',
];

for (const md of payloads) {
    console.log('MD:  ', md);
    console.log('HTML:', marked.parse(md, { async: false }));
    console.log();
}

Actual output:

MD:   [click me](javascript:alert(document.cookie))
HTML: <p><a href="javascript:alert(document.cookie)">click me</a></p>

MD:   [click me](JaVaScRiPt:alert(1))
HTML: <p><a href="JaVaScRiPt:alert(1)">click me</a></p>

MD:   [legit](https://example.com)
HTML: <p><a href="https://example.com">legit</a></p>

Both dangerous payloads render as live, unescaped, clickable <a href="javascript:..."> links, exactly the same shape of output as marked.parse() inside either Svelte component would produce, since neither component passes any extra options or applies any post-processing before {@html} renders it.

Two distinct exploitation paths, different severity

Path 1, MarkdownEditor.svelte, self-XSS / collaborator XSS. Anyone with page-edit access who types [x](javascript:alert(1)) into the editor sees it rendered as a live clickable link in their own preview pane immediately, no save required. On its own this is "self-XSS", limited value as an attack against yourself. But the product has real-time collaborative editing (multiple users editing the same document with live presence), if a lower-privileged collaborator's typed content is reflected into a higher-privileged collaborator's (an admin's) preview pane in that shared session, this becomes a real cross-privilege attack, a content editor targeting an admin who happens to be co-editing. I have not verified the exact data flow of the collaborative editing feature (I don't have a live multi-session environment to test it in), so I'm flagging this as a plausible but unconfirmed escalation of Path 1, not a demonstrated one.

Path 2, MarkdownModal.svelte via plugin/theme changelogs, no site access required. This is the more clearly severe path. Any plugin or theme listed in Grav's package ecosystem (GPM) can supply a changelog, which is unauthenticated, third-party-authored content by nature, that's the whole point of a plugin marketplace. If any published plugin or theme's changelog contains a javascript: link (whether the author is malicious, or a legitimate plugin's repository/changelog source gets compromised), any Grav admin who opens that plugin's detail page and views its changelog in Admin2 gets that payload executed in their authenticated admin session. This requires zero access to the target Grav site, only that an admin of some Grav site, anywhere, browses that plugin's info in the marketplace UI.

Impact

Cross-site scripting executing in the browser context of a logged-in Admin2 user, in Path 2's case triggerable by an unrelated third party (any plugin/theme publisher) against any admin who views that package's changelog, with no prior access to the victim's site. Standard XSS impact applies: session/token theft (recall the API plugin issues short-lived access/refresh tokens for SPA use, exactly the kind of credential a script running in this context could read and exfiltrate if they're accessible to JS, e.g. stored in localStorage rather than an httpOnly cookie, worth double-checking as a related but separate concern), arbitrary actions performed as the admin against the Grav API, full admin session takeover.

Suggested fix

Sanitize the HTML marked.parse() produces before passing it to {@html}, in both components. The standard, well-supported approach is DOMPurify:

import DOMPurify from 'dompurify';
...
const previewHtml = $derived(showPreview ? DOMPurify.sanitize(marked.parse(resolveImagePaths(value || ''), { async: false }) as string) : '');

and the equivalent change in MarkdownModal.svelte. DOMPurify strips dangerous URI schemes from href/src attributes by default (and is configurable if legitimate non-http(s) schemes like mailto:/tel: need to stay allowed). Given this exact marked.parse() + {@html} pattern appears in exactly two places, a single shared helper (e.g. renderSafeMarkdown(text: string): string) wrapping both the parse and the sanitize step, used by both components instead of each calling marked.parse() directly, would prevent a third call site from reintroducing this gap later.

=========================================================== CWE FIELD =========================================================== CWE-79, Improper Neutralization of Input During Web Page Generation (Cross-site Scripting)

=========================================================== CVSS CALCULATOR SELECTIONS (v3.1) =========================================================== Scoring Path 2 (the more severe, more clearly reachable path), since it requires no privileges on the target site at all:

Attack Vector: Network Attack Complexity: Low Privileges Required: None User Interaction: Required Scope: Changed Confidentiality: High Integrity: High Availability: None

Resulting vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N Approximate score: 8.6, severity High (hand-computed, please re-derive via the calculator UI)

Note for the maintainer: Privileges Required is None because the attacker (a plugin/theme publisher) needs no account or access on the victim's Grav install at all, only a listed package with attacker-controlled changelog content. User Interaction is Required because the admin has to open that specific package's detail modal. I'd treat Path 1 (the editor live-preview self/collaborator-XSS) as lower severity on its own, roughly comparable to a standard authenticated self-XSS, unless the collaborative-editing cross-user reflection is confirmed, in which case it should be rescored similarly to Path 2 with Privileges Required Low instead of None.

=========================================================== SEVERITY FIELD =========================================================== High

Affected versions

References

GitHub · getgrav/grav