Skip to content
XSS Disclosed report Beginner CVE-2013-0256

XSS exploit of RDoc documentation generated by rdoc (CVE-2013-0256)

RDoc's paragraph formatter inserted raw paragraph text into generated HTML without escaping, so a crafted documentation source file could inject script tags into the output. An attacker who could get a malicious file processed by rdoc could have arbitrary script run in the browser of anyone viewing the generated documentation.

sighook Follow

Originally disclosed on HackerOne

Medium 5.4 View original
  • Disclosed after 2 months

The exploit exists in paragraph formatting that allows malicious code to be injected into the generated documentation.

PoC

For example, let's create the example file with the following content:

\x[\<script>alert(1);</script>\]

Now, run rdoc:

Shell
rdoc --all

The output html will have the following injected javascript code:

HTML
<main role="main" aria-label="Page example">

<p>x[<script>alert(1);</script>]</p>

</main>

Solution

I may be wrong with the solution, but I want to be more helpful :) At first glance, the vulnerable code is here:

RB
  def accept_paragraph paragraph
    @res << "\n<p>"
    text = paragraph.text @hard_break
    text = text.gsub(/\r?\n/, ' ')
    @res << to_html(text) # <====== CGI.escapeHTML(text)) ???
    @res << "</p>\n"
  end

I suppose we should sanitize the output. For example, after changing text to CGI.escapeHTML(text) I've got the following result:

HTML
<main role="main" aria-label="Page example">

<p>x[&lt;script&gt;alert(1);&lt;/script&gt;]</p>

</main>

I hope this doesn't break anything. ^_^

Impact

A cross-site scripting (XSS) vulnerability allows attackers to execute arbitrary web scripts or HTML via a crafted payload.

Attachments

23-05-08-16_21_41.png
23-05-08-16_21_41.png From the original on HackerOne

The original report as published on HackerOne, by sighook. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

The paragraph handler concatenated the paragraph text into the HTML output without HTML-escaping it.

Impact

Script supplied through documentation source could execute in the browser of anyone viewing the generated HTML, though the text does not demonstrate an attack against a hosted service.

What the attacker needed

Ability to supply a file processed by rdoc; victim views the generated HTML

The fix

The paragraph text should be HTML-escaped before being written into the output, which the author shows produces escaped entities instead of live markup.

How it was found

  1. Create a source file containing a paragraph with an embedded script tag
  2. Run rdoc over the file to generate HTML documentation
  3. Open the generated page and observe the script tag rendered as live markup

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.

RDoc is a tool that turns source code comments into HTML documentation pages. The tool copied text straight into the web page without neutralising characters like angle brackets, so a line of text could become a real script tag. When someone opened the generated page, their browser would run that script as if the site had written it.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More by sighook

View all

10 more disclosed reports, best first.

More from Ruby

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.