Skip to content
XSS Disclosed report Intermediate CVE-2019-11744

title.innerHTML = "</title><foo>" parses <foo> as a tag

Firefox renders HTML assigned to the innerHTML property of an element created with document.createElement() or createElementNS() immediately, before the element is inserted into the DOM. An attacker could exploit this to execute JavaScript via an SVG onload handler, even when the element is a title tag, by escaping its context with a closing title tag.

Rakesh Follow

Originally disclosed on Mozilla

  • Fixed in 39 days
  • Paid in 39 days
  • Disclosed after 39 days
Text
When creating any element (except "template" and "script" tags) using "document.createElement()" and "document.createElementNS()" function the provided HTML code gets rendered directly. Ideally the HTML code should not get rendered until it is manually inserted into DOM using "appendChild()" or similar function. I tested this issue on Chrome, Opera and Safari, they do not render the HTML code directly, also the HTML specs does not explicitly states to render the HTML code directly when creating the Elements. (Reference : https://dom.spec.whatwg.org/#dom-document-createelement)

For Example :
document.createElement("AnyElementBlahBlah").innerHTML="<svg/onload=alert()>"

This code would execute "alert()" function directly. We did not even need to insert the element in DOM.

Here's another interesting example : 
document.createElement("title").innerHTML="</title><svg/onload=alert()>"

Here the content of "title" element should not be rendered at all but we are able to escape out of "title" tag context by prepending a closing "title" tag as shown in above example. Using this trick we can render our HTML code inside "title" element as well and execute our Javascript code. Damn.

The same flaw applies to "document.createElementNS()" as well. 

For example : 
document.createElementNS("http://www.w3.org/1999/xhtml", "title").innerHTML="</title><svg onload=alert()>"


Impact:

It can introduce XSS vulnerability to many web applications because HTML specs does not states to render HTML such a way and also the other browsers does not follow this practice so technically it would be safe to allow untrusted input like "document.createElement("title").innerHTML='UntrustedUserInput' " as long as the input is verified before inserting it to DOM, however for Firefox that's not the case because Firefox will render the Untrusted Input directly which would lead to execution of malicious Javascript as well.

Tested On : 
- Firefox 68.0b13 (64-bit) 
- Firefox 67.0.4 (64-bit)

The original report as published on Mozilla's Bugzilla, by Rakesh. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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 Firefox's implementation of innerHTML on detached elements parses and executes scripts immediately, contrary to the specification and other browsers.

Impact

This could introduce XSS vulnerabilities in web applications that rely on the specification and other browsers' behaviour, as untrusted input assigned to innerHTML of a detached element would execute in Firefox.

What the attacker needed

Victim uses Firefox; application assigns untrusted input to innerHTML of a…

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.

When you create a new HTML element in JavaScript, you normally expect it to stay inert until you add it to the page. This report shows that in Firefox, setting the innerHTML of such an element immediately runs any scripts inside it, even if the element is never added to the page. That means a website that thought it was safe by only creating elements and setting their HTML could be tricked into running malicious code.

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 Rakesh

View all

1 more disclosed report, best first.

More from Mozilla

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.