ActionText `to_markdown` still allows `javascript:` links in kramdown via Rails-generated table cells after PR #58754
ActionText's to_markdown method wrote the contents of code and pre elements without escaping, relying on the code span delimiter to keep them inert. When such code sat in a table cell and began with whitespace, kramdown rebuilt the span with a single backtick and rendered a javascript: link that to_markdown would otherwise refuse to produce.
- Disclosed after 7 days
Summary by the program
ActionText::Content#to_markdown writes the text of <code> and <pre> elements unescaped and relies on the code span delimiter to keep it inert. For code in a table cell that starts with two or more spaces or a tab, such as <td><code> [click](javascript:alert(1))</code></td>, it emitted a code span delimited by two backticks. That Markdown is correct, and Commonmarker and Redcarpet render it as code. kramdown rebuilds the span with a single backtick when it splits the table row into cells, then fails to open it, and renders a javascript: link that to_markdown refuses to emit from an <a> element.
We closed the report as Informative because the link comes from kramdown misparsing correct Markdown. We changed to_markdown in rails/rails#58956 to strip leading and trailing whitespace from code spans in table cells, which avoids the kramdown behavior. to_markdown is not yet in any released version of Rails.
Thanks to @deah313 for the report.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the converter relied on the code span delimiter to neutralise unescaped code content, without accounting for a downstream parser that rewrites spans inside table cells.
What the attacker needed
Content rendered by kramdown; code inside a table cell; code begins with whitespace
The fix
It was addressed by changing to_markdown to strip leading and trailing whitespace from code spans in table cells, avoiding the kramdown behaviour.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.