Possible Mutation XSS or DOM XSS in innerHTML method due to incorrect parsing <template>
The innerHTML parser in Firefox mishandles a template element inside a select element, allowing an SVG onload handler to execute even though scripts should not run inside select. An attacker could execute JavaScript if they can inject HTML into a select via innerHTML.
- Fixed in 34 days
- Paid in 55 days
- Disclosed after 34 days
Description
===
When doing some fuzzing, I discovered that it is possible to execute scripts inside <select> element when using innerHTML method. The bug is that the parsing gets broken after injecting <template> element.
Generally, no scripts should be executed inside <select> element, and the only allowed tags seem to be <option>, <optgroup>, <script>, <template>. None of these can execute javascript when called through innerHTML, and the bug seems to be only working in the Firefox within browsers that I tested this on.
Steps
===
Reproduction steps (Firefox Browser 71.0 (64-bit), Windows 10):
var s = document.createElement('select');
document.body.appendChild(s);
s.innerHTML = '<svg/onload=alert(/wont_trigger/)></svg><template></template><svg/onload=alert(/will_trigger/)></svg>'
I also discovered that the issue is very innerHTML specific and will not work when the element is inserted directly through insertAdjacentHTML, document.write() or
<select><template></template><svg onload=alert()></svg></select> as a HTML code.
Impact
===
I don't know what's the biggest impact yet, but I fell that there must a serious bug in the parser that allows inserting any HTML after <template></template> when using innerHTML, even if the element could not be put there otherwise.
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 HTML parser incorrectly handles the template element inside select when using innerHTML, allowing subsequent content to be parsed as if it were outside the select, enabling script execution.
Impact
An attacker could execute arbitrary JavaScript in the context of a vulnerable page if they can inject HTML into a select element via innerHTML, but the report notes the issue is specific to Firefox and innerHTML.
What the attacker needed
Victim uses Firefox; attacker can inject HTML into a select via innerHTML
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.
Normally, a select dropdown should not run any scripts, even if you put HTML inside it. This report found that in Firefox, adding a template tag inside a select breaks the parser so that a script hidden in an SVG image tag runs. That means if a website lets an attacker control what goes into a select using innerHTML, the attacker could run their own code.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.