Skip to content
XSS Write-up Advanced

Achieving the impossible: XSS in innerHTML without equals

portswigger.net

Published on portswigger.net

I'm delighted to introduce Masato Kinugawa as a guest web security researcher on the PortSwigger research channel. Masato is a well known web security expert who has found countless high impact bugs and amazingly he solved one of our "impossible" labs.

The author, on portswigger.net

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 8 min read.

Context

In 2020, Gareth Heyes compiled a list of "impossible labs": injection scenarios in which JavaScript execution was considered impossible. One of them, "innerHTML context but no equals allowed", asks whether arbitrary JavaScript can be executed when an injection lands in an innerHTML context but the equals sign is not permitted. That challenge had long been treated as unsolvable.

This post is a guest write-up by Masato Kinugawa, introduced by Gareth Heyes on the PortSwigger research channel, describing how a newly introduced HTML element made the challenge solvable. The payload he found is:

Text
<body><script>document.body.innerHTML=`<select><selectedcontent></selectedcontent><option><svg><script>alert(1)<\/script>`;</script>

That payload no longer works in Chrome because of a behaviour change introduced in Chrome 153, but the author confirmed it still works in Safari 27.2, the latest version at the time of writing.

Gareth Heyes
Gareth Heyes From the original on portswigger.net

Setup

The work is browser research rather than testing against a specific application. The relevant preconditions are:

  1. An injection point where attacker-controlled markup is assigned to innerHTML (directly, or through a sink that behaves the same way).
  2. A context in which the equals sign is not allowed in the injected payload.
  3. A browser that implements the <selectedcontent> element. The author tested Chrome and Safari; the final vector worked in Safari 27.2, and the earlier SVG variant worked in Chrome 157 before the Chrome 153 change.

The author also provides a lab page to try the final vector in Safari:

Text
https://portswigger-labs.net/impossible-labs/innerHTML-no-equals.php?x=%3Cselect%3E%3Cselectedcontent%3E%3C/selectedcontent%3E%3Coption%3E%3Csvg%3E%3Cscript%3Ealert%281%29%3C/script%3E
Shows a man surrounded by lasers reaching for alert(1)
Shows a man surrounded by lasers reaching for alert(1) From the original on portswigger.net

Finding it

The starting point was a DOMPurify bypass disclosed in May 2026 by Kabir Acharya. What caught the author's attention was its use of the <selectedcontent> element, which had been introduced relatively recently in Chrome and Safari and which he had never seen used in an XSS vector before. The bypass is documented in the "Attack Classes & Bypass History" section of the DOMPurify wiki, under "engine deferred mutation selectedcontent".

Despite its harmless-sounding name, <selectedcontent> has an unusual capability. Given this HTML:

HTML
<select><button><selectedcontent></selectedcontent></button><option><b>option 1</b></option><option selected><b>option 2</b></option></select>

inspecting the resulting DOM through innerHTML shows:

HTML
<select><button><selectedcontent><b>option 2</b></selectedcontent></button><option><b>option 1</b></option><option selected=""><b>option 2</b></option></select>

The contents of option 2, including its HTML elements, have been copied into <selectedcontent>. The element clones the child nodes of the currently selected <option>; here option 2 is selected by default because it carries the selected attribute. Before this, no HTML element could perform that kind of cloning on its own without JavaScript. Inspired by Kabir's discovery, the author began investigating whether the same behaviour could make other previously impossible things possible.

Exploitation

Step 1: execute a script with no closing tag

Before looking at the innerHTML case, the author found that JavaScript could be executed through this HTML:

HTML
<select><button><selectedcontent></selectedcontent></button><option><script>alert(1)

The document ends immediately after <script>alert(1). Opened in Chrome or Safari, this triggers an alert exactly once. Normally an unclosed <script> tag that reaches the end of the document without an explicit </script> is not executed; here it is.

The explanation is the selection rule: inside a <select>, the first <option> is selected by default when no selected attribute is present. The <option> containing the <script> element is therefore selected, the browser clones its child nodes into <selectedcontent>, and the Chrome and Safari implementations execute the cloned <script> element. Replacing alert(1) with alert(document.currentScript.parentNode.tagName) returns SELECTEDCONTENT, confirming that the executing script is the clone and that its parent is the <selectedcontent> element.

Step 2: remove the slash

After the author shared this vector on social media, Mathias Karlsson helped eliminate / entirely from it:

HTML
<select><button><selectedcontent><button><option><script>alert(1)

This executes JavaScript without whitespace, / or =. The line breaks in the payload are only for readability and can be removed.

Step 3: survive trailing page content with SVG

The vector has a significant limitation: if additional content follows it, that content becomes part of the <script> block, making a JavaScript syntax error highly likely, which severely limits its usefulness in real-world XSS scenarios. SVG solves this:

HTML
<select><button><selectedcontent><button><option><svg><script>alert(1)<foo> <!-- The following is the legitimate page content --><div some-attr="123">test</div></body></html>

Unlike a normal HTML <script> element, an SVG <script> element lets the HTML parser interpret the following <foo> as a start tag, so the HTML after <foo> does not become part of the JavaScript code. The Chrome and Safari implementations still execute the SVG <script> element cloned into <selectedcontent>. Arbitrary JavaScript therefore runs without whitespace, / or =, even when normal HTML content follows the vector. This particular set of constraints is not one of the impossible lab's, but to the author's knowledge no vector was previously known that could execute JavaScript in modern browsers without whitespace, / or =. It worked not only in Safari but also in Chrome 157, the latest version at the time of writing.

Step 4: the innerHTML payload

While exploring whether the previous vector could be extended, the author casually tried assigning almost the same HTML to innerHTML. To his surprise, it triggered JavaScript execution in Chrome:

Text
<body><script>document.body.innerHTML=`<select><selectedcontent></selectedcontent><option><svg><script>alert(1)<\/script>`;</script>

This is the payload that solves the "innerHTML context but no equals allowed" lab.

Step 5: confirming which conditions matter

<script> elements inserted via innerHTML are prevented from executing by the specification. For example, the following does not trigger an alert:

HTML
<body><script>document.body.innerHTML = "<script>alert(/not-executed/)<\/script>";</script>

If such scripts could execute, the lab could have been solved with just <script>alert(1)</script>, without any equals sign. In the working vector, the <script> element clearly executes, so something differs from simply inserting a <script> element.

The key difference is that assigning the HTML to innerHTML causes a clone of the <script> element to be created inside <selectedcontent>, and the original <script> element is inside <svg>, so it is created in the SVG namespace. Removing <svg> prevents execution:

Text
<body><script>document.body.innerHTML=`<select><selectedcontent></selectedcontent><option><script>alert(/not executed/)<\/script>`;</script>

Removing <selectedcontent> also prevents execution:

HTML
<body><script>document.body.innerHTML = "<svg><script>alert(/not executed/)<\/script>";</script>

Both conditions are therefore necessary: the <script> element must be created in the SVG namespace rather than the HTML namespace, and it must be cloned by <selectedcontent>.

Step 6: reproducing the clone with cloneNode

According to the specification, when <selectedcontent> clones the child nodes of the selected <option> it uses the same DOM cloning algorithm as cloneNode(true). The author reproduced the behaviour with that function. The following code clones a node containing an SVG <script> inserted via innerHTML and appends the clone to the DOM; the script executed when the clone was appended:

JavaScript
document.body.innerHTML = `  <div id="source">    <svg><script>alert()<\/script></svg>  </div>  <div id="target"></div>`;
clone=source.cloneNode(true);
target.append(clone);

Removing <svg> prevents the script from executing:

JavaScript
document.body.innerHTML = `  <div id="source">    <script>alert(/not executed/)<\/script>  </div>  <div id="target"></div>`;
JavaScript
clone=source.cloneNode(true);
JavaScript
target.append(clone);

In other words, cloning an SVG <script> element apparently allowed a script that had not executed in the original element to execute. That cloning behaviour was the key to making the vector work.

Root cause

The behaviour appears to have been unintended and was subsequently changed in Chromium. According to the commit that introduced the change, the relevant mechanism is the already started flag defined in the HTML Standard, which affects script execution. The flag was set to true for HTML <script> elements created via innerHTML, but remained false for SVG <script> elements. That difference appears to have caused the observed behaviour: the SVG script was not marked as already started, so when <selectedcontent> cloned it, the clone could execute.

Chromium was changed so that already started is also set to true for SVG <script> elements created via innerHTML, which prevents the technique from working there. It still works in Safari 27.2.

Impact

Where the technique works, an attacker who controls markup that reaches an innerHTML sink can execute arbitrary JavaScript even when the equals sign is not allowed in the injection, which defeats a constraint that had been considered sufficient to make the scenario unexploitable. The author's earlier SVG variant additionally executes without whitespace, / or =, and survives legitimate HTML content following the injection point. The impact is bounded by the browser: the final vector no longer works in Chrome after the change introduced in Chrome 153, and the author confirmed it only in Safari 27.2.

Fix

The author notes that the technique still works in Safari 27.2.

Variants to test

  1. <selectedcontent> cloning in other sinks. Assign markup containing <select><selectedcontent></selectedcontent><option><svg><script>... to any DOM sink that parses HTML, not only innerHTML. A positive result is script execution from the cloned element, which you can confirm by alerting document.currentScript.parentNode.tagName and seeing SELECTEDCONTENT.
  2. Namespace checks. Take any working clone-based vector and remove <svg>, then remove <selectedcontent>. If execution stops in both cases, the target browser still has the namespace and cloning preconditions the author describes.
  3. Character-restricted contexts. Reuse the whitespace-free, slash-free, equals-free form <select><button><selectedcontent><button><option><svg><script>alert(1)<foo> where a filter blocks those characters. A positive result is an alert followed by the trailing page content being parsed as HTML rather than swallowed into the script.
  4. Sanitiser coverage. Run the payloads through any HTML sanitiser in front of the sink.
  5. Browser matrix. Test the same payload in each engine and version you care about. A positive result is execution in a browser that has not yet adopted the already started change for SVG scripts created via innerHTML.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 18 min read.

What happened, in plain words

Imagine a website that lets you type something into a box, and that text later gets placed into the page as if it were part of the page's own code. If you can sneak in a small piece of code that the browser runs, you have what security people call cross-site scripting, or XSS. It is one of the oldest and most common web bugs: the browser trusts the text as if the site itself had written it.

For years, researchers kept a list of situations where they believed XSS was impossible. One entry on that list was called "innerHTML context but no equals allowed". The idea was: suppose your text lands in a particular spot in the page, and the site's filter also blocks the equals sign (=). Surely nothing dangerous can be done then? The equals sign is used all over JavaScript, so blocking it seemed like a strong defence.

This article is a guest post by Masato Kinugawa, introduced by Gareth Heyes on the PortSwigger research channel. Masato found a way to run JavaScript in exactly that situation, using a brand-new HTML element called <selectedcontent>. The payload he found is:

Text
<body><script>document.body.innerHTML=`<select><selectedcontent></selectedcontent><option><svg><script>alert(1)<\/script>`;</script>

That payload no longer works in Chrome because of a behaviour change introduced in Chrome 153, but the author confirmed it still works in Safari 27.2, the latest version at the time of writing.

Gareth Heyes
Gareth Heyes From the original on portswigger.net

Before going further, a few words on the pieces involved, because the rest of the article leans on them.

  • HTML is the language that describes what is on a web page: headings, buttons, dropdown lists, images. A browser reads HTML and turns it into the page you see.
  • JavaScript is the programming language that runs inside the browser. It is what makes pages interactive. alert(1) is the classic tiny JavaScript program that pops up a box saying "1". Security researchers use it as a harmless proof that code ran.
  • innerHTML is a property of every element on a page. In JavaScript you can write document.body.innerHTML = "..." to replace the contents of the page body with new HTML. It is a convenient way for a site to build parts of the page from text. It is also a classic place where XSS happens, because if an attacker's text ends up on the right-hand side, the browser treats it as real HTML.
  • A filter is code on the server or in the browser that inspects incoming text and removes or blocks dangerous parts. Blocking the equals sign is an example of a filter rule.
  • A browser engine is the part of the browser that reads HTML and runs JavaScript. Chrome uses one engine (Chromium), Safari uses another (WebKit). They mostly behave the same, but small differences matter a lot in this story.

Setup

This is browser research, not an attack on one particular website. There is no specific company or server being tested. The author is studying how browsers behave when they are handed certain HTML. The preconditions are:

  1. An injection point where text controlled by an attacker is assigned to innerHTML (directly, or through some other feature that behaves the same way).
  2. A context in which the equals sign is not allowed in the injected payload.
  3. A browser that implements the <selectedcontent> element. The author tested Chrome and Safari; the final vector worked in Safari 27.2, and the earlier SVG variant worked in Chrome 157 before the Chrome 153 change.

The author also provides a lab page to try the final vector in Safari:

Text
https://portswigger-labs.net/impossible-labs/innerHTML-no-equals.php?x=%3Cselect%3E%3Cselectedcontent%3E%3C/selectedcontent%3E%3Coption%3E%3Csvg%3E%3Cscript%3Ealert%281%29%3C/script%3E

That long URL is just the lab page with the payload tucked into the x parameter. The %3C, %3E, %28 and %29 pieces are how special characters like <, >, ( and ) are written inside a URL so they do not confuse the browser. Decoded, the parameter is the same <select><selectedcontent></selectedcontent><option><svg><script>alert(1)</script> payload you have already seen. Opening the link in Safari runs the test.

Shows a man surrounded by lasers reaching for alert(1)
Shows a man surrounded by lasers reaching for alert(1) From the original on portswigger.net

Finding it

The starting point was a DOMPurify bypass disclosed in May 2026 by Kabir Acharya. DOMPurify is a popular JavaScript library that websites use to clean HTML before putting it on a page: you give it messy HTML, it gives you back a safe version with dangerous tags removed. A bypass means finding input that gets past the cleaner and still does something harmful. What caught the author's attention was that this bypass used the <selectedcontent> element, which had been introduced relatively recently in Chrome and Safari and which he had never seen used in an XSS vector before. The bypass is documented in the "Attack Classes & Bypass History" section of the DOMPurify wiki, under "engine deferred mutation selectedcontent".

Despite its harmless-sounding name, <selectedcontent> has an unusual capability. Given this HTML:

HTML
<select><button><selectedcontent></selectedcontent></button><option><b>option 1</b></option><option selected><b>option 2</b></option></select>

Let us read that piece by piece. <select> is a dropdown list. Inside it there is a <button> (a clickable button) and, inside the button, an empty <selectedcontent> element. Then come two <option> elements, which are the choices in the dropdown. The first option contains bold text "option 1". The second contains bold text "option 2" and carries the attribute selected, which tells the browser "this is the one chosen by default".

Inspecting the resulting DOM through innerHTML shows:

HTML
<select><button><selectedcontent><b>option 2</b></selectedcontent></button><option><b>option 1</b></option><option selected=""><b>option 2</b></option></select>

The DOM is the browser's internal tree-shaped model of the page: every element becomes a node in that tree, and innerHTML lets you read the tree back as text. Compare the two blocks. The <selectedcontent> element, which was empty in the input, now contains <b>option 2</b>. The contents of option 2, including its HTML elements, have been copied into <selectedcontent>. The element clones the child nodes of the currently selected <option>; here option 2 is selected by default because it carries the selected attribute. Before this, no HTML element could perform that kind of cloning on its own without JavaScript. Inspired by Kabir's discovery, the author began investigating whether the same behaviour could make other previously impossible things possible.

A useful everyday comparison: think of <selectedcontent> as a small photocopier built into the dropdown. Whatever is currently chosen in the list gets photocopied into the button, automatically, with no JavaScript involved. The photocopy includes not just the words but the formatting (the <b> tags).

Exploitation

Step 1: execute a script with no closing tag

Before looking at the innerHTML case, the author found that JavaScript could be executed through this HTML:

HTML
<select><button><selectedcontent></selectedcontent></button><option><script>alert(1)

Line by line: a <select> dropdown, a <button> containing an empty <selectedcontent>, and one <option> whose content is a <script> tag holding alert(1). Notice there is no </script> closing tag and no closing tags for the other elements either. The document ends immediately after <script>alert(1).

Opened in Chrome or Safari, this triggers an alert exactly once. That is surprising. Normally an unclosed <script> tag that reaches the end of the document without an explicit </script> is not executed; the browser treats it as incomplete and ignores it. Here it runs anyway.

The explanation is the selection rule: inside a <select>, the first <option> is selected by default when no selected attribute is present. The <option> containing the <script> element is therefore selected, the browser clones its child nodes into <selectedcontent>, and the Chrome and Safari implementations execute the cloned <script> element. In other words, the original script was never run, but the photocopy of it was, and the browser treated the photocopy as a fresh script that had not been run before.

How do we know it is the clone that runs and not the original? Replacing alert(1) with alert(document.currentScript.parentNode.tagName) returns SELECTEDCONTENT, confirming that the executing script is the clone and that its parent is the <selectedcontent> element. document.currentScript is a built-in way for a running script to refer to itself; .parentNode is the element that contains it; .tagName is that element's name. The answer, SELECTEDCONTENT, tells us the script that ran lives inside <selectedcontent>, which is the copy, not the original inside <option>.

Step 2: remove the slash

After the author shared this vector on social media, Mathias Karlsson helped eliminate / entirely from it:

HTML
<select><button><selectedcontent><button><option><script>alert(1)

This executes JavaScript without whitespace, / or =. The line breaks in the payload are only for readability and can be removed.

Why does that matter? Many filters block a list of characters they consider dangerous, often including spaces, slashes and equals signs. A payload that needs none of them slips past more filters. The author does not spell out the exact parsing steps; what matters is the result: the same alert, with fewer forbidden characters.

Step 3: survive trailing page content with SVG

The vector has a significant limitation: if additional content follows it, that content becomes part of the <script> block, making a JavaScript syntax error highly likely, which severely limits its usefulness in real-world XSS scenarios. Think about it: the browser is still waiting for </script>, so everything after the payload, including the site's own legitimate HTML, gets swallowed into the script as if it were JavaScript. A syntax error means nothing runs.

SVG solves this. SVG stands for Scalable Vector Graphics: it is a way to describe drawings (lines, shapes, icons) in HTML-like markup. Browsers treat SVG content slightly differently from ordinary HTML, and that difference is what the author exploits.

HTML
<select><button><selectedcontent><button><option><svg><script>alert(1)<foo> <!-- The following is the legitimate page content --><div some-attr="123">test</div></body></html>

Unlike a normal HTML <script> element, an SVG <script> element lets the HTML parser interpret the following <foo> as a start tag, so the HTML after <foo> does not become part of the JavaScript code. The comment <!-- The following is the legitimate page content --> and the <div some-attr="123">test</div></body></html> after it stand in for whatever real page content follows the injection point. The Chrome and Safari implementations still execute the SVG <script> element cloned into <selectedcontent>. Arbitrary JavaScript therefore runs without whitespace, / or =, even when normal HTML content follows the vector.

This particular set of constraints is not one of the impossible lab's, but to the author's knowledge no vector was previously known that could execute JavaScript in modern browsers without whitespace, / or =. It worked not only in Safari but also in Chrome 157, the latest version at the time of writing.

Step 4: the innerHTML payload

While exploring whether the previous vector could be extended, the author casually tried assigning almost the same HTML to innerHTML. To his surprise, it triggered JavaScript execution in Chrome:

Text
<body><script>document.body.innerHTML=`<select><selectedcontent></selectedcontent><option><svg><script>alert(1)<\/script>`;</script>

This is the payload that solves the "innerHTML context but no equals allowed" lab. Let us walk through it.

  • <body> starts the page body.
  • <script> opens a script block that the browser will run as JavaScript.
  • document.body.innerHTML= assigns new HTML to the body. The value is written between backticks, which in JavaScript are a way to write a string of text (a template literal).
  • Inside the backticks is the HTML being injected: a <select>, an empty <selectedcontent>, an <option>, then <svg><script>alert(1)<\/script>.
  • The \/ inside the injected script is an escaped slash. In JavaScript, \/ means just /, so the browser sees </script> and closes the injected script properly. Writing it as \/ stops the outer script block from ending too early, which would otherwise break the payload.
  • The final </script> closes the outer script that does the assignment.

Notice what is missing: there is no equals sign anywhere in the injected HTML. The only = is in the outer JavaScript assignment, which is the site's own code, not the attacker's input. That is why this defeats the "no equals allowed" rule.

Step 5: confirming which conditions matter

<script> elements inserted via innerHTML are prevented from executing by the specification. The specification is the written rulebook that browser makers agree to follow, so that pages behave the same everywhere. For example, the following does not trigger an alert:

HTML
<body><script>document.body.innerHTML = "<script>alert(/not-executed/)<\/script>";</script>

Here the outer script assigns a <script>alert(/not-executed/)</script> to the body. The browser inserts the element into the page, but deliberately does not run it. The /not-executed/ text is just a label inside the alert so you can tell which test fired; it never appears because nothing runs.

If such scripts could execute, the lab could have been solved with just <script>alert(1)</script>, without any equals sign. In the working vector, the <script> element clearly executes, so something differs from simply inserting a <script> element.

The key difference is that assigning the HTML to innerHTML causes a clone of the <script> element to be created inside <selectedcontent>, and the original <script> element is inside <svg>, so it is created in the SVG namespace. A namespace is a label that tells the browser which family of markup an element belongs to. HTML elements and SVG elements can share names but are treated as different kinds of thing. The browser's rule about not running scripts inserted via innerHTML applies to the HTML family; the SVG family was handled differently.

Removing <svg> prevents execution:

Text
<body><script>document.body.innerHTML=`<select><selectedcontent></selectedcontent><option><script>alert(/not executed/)<\/script>`;</script>

This is the same payload with <svg> taken out. The <script> is now an ordinary HTML script, the browser refuses to run it, and no alert appears.

Removing <selectedcontent> also prevents execution:

HTML
<body><script>document.body.innerHTML = "<svg><script>alert(/not executed/)<\/script>";</script>

Here the SVG script is present, but there is no <selectedcontent> to clone it, so again nothing runs.

Both conditions are therefore necessary: the <script> element must be created in the SVG namespace rather than the HTML namespace, and it must be cloned by <selectedcontent>. Remove either one and the trick collapses. This is a useful way to think about any bug: change one ingredient at a time and see whether the result still happens. If it stops, that ingredient was essential.

Step 6: reproducing the clone with cloneNode

According to the specification, when <selectedcontent> clones the child nodes of the selected <option> it uses the same DOM cloning algorithm as cloneNode(true). cloneNode is a built-in JavaScript function that makes a copy of an element; the true means "copy everything inside it too, not just the outer tag". The author reproduced the behaviour with that function. The following code clones a node containing an SVG <script> inserted via innerHTML and appends the clone to the DOM; the script executed when the clone was appended:

JavaScript
document.body.innerHTML = `  <div id="source">    <svg><script>alert()<\/script></svg>  </div>  <div id="target"></div>`;
clone=source.cloneNode(true);
target.append(clone);

Line by line:

  1. The first line puts two boxes on the page: a <div> with the id source, containing an SVG <script> that calls alert(), and an empty <div> with the id target. Because this HTML arrives via innerHTML, the SVG script inside source does not run at this point.
  2. clone=source.cloneNode(true) makes a full copy of the source element and stores it in a variable called clone. The copy includes the SVG script.
  3. target.append(clone) puts that copy inside the target box. At this moment the copied script runs, and the alert appears.

So the original script never ran, but its copy did. That is the same pattern as the <selectedcontent> behaviour, reproduced with ordinary JavaScript functions.

Removing <svg> prevents the script from executing:

JavaScript
document.body.innerHTML = `  <div id="source">    <script>alert(/not executed/)<\/script>  </div>  <div id="target"></div>`;
JavaScript
clone=source.cloneNode(true);
JavaScript
target.append(clone);

These three blocks are the same experiment with the <svg> wrapper removed. The first builds the page with a plain HTML script inside source; the second copies it; the third appends the copy. This time nothing runs, because the browser's rule against running scripts inserted via innerHTML applies to the HTML family, and copying does not change that.

In other words, cloning an SVG <script> element apparently allowed a script that had not executed in the original element to execute. That cloning behaviour was the key to making the vector work.

Root cause

The behaviour appears to have been unintended and was subsequently changed in Chromium. A commit is a recorded change to a codebase; browser makers publish them so others can see what changed and why. According to the commit that introduced the change, the relevant mechanism is the already started flag defined in the HTML Standard, which affects script execution. A flag here is simply a true/false marker the browser keeps for each script element. The flag was set to true for HTML <script> elements created via innerHTML, but remained false for SVG <script> elements. That difference appears to have caused the observed behaviour: the SVG script was not marked as already started, so when <selectedcontent> cloned it, the clone could execute.

A simple comparison: imagine a cinema where every ticket is stamped "used" as you enter. A script inserted via innerHTML gets stamped immediately, so it cannot be used again. An SVG script, because of a gap in the rules, was not stamped. When <selectedcontent> made a copy, the copy looked like a fresh, unused ticket, and the browser let it in.

Chromium was changed so that already started is also set to true for SVG <script> elements created via innerHTML, which prevents the technique from working there. It still works in Safari 27.2.

Impact

Where the technique works, an attacker who controls markup that reaches an innerHTML sink can execute arbitrary JavaScript even when the equals sign is not allowed in the injection, which defeats a constraint that had been considered sufficient to make the scenario unexploitable. A sink is the place in the code where untrusted text finally gets used in a way that matters, here the assignment to innerHTML. The author's earlier SVG variant additionally executes without whitespace, / or =, and survives legitimate HTML content following the injection point. The impact is bounded by the browser: the final vector no longer works in Chrome after the change introduced in Chrome 153, and the author confirmed it only in Safari 27.2.

Fix

In the cinema comparison, the gap in the stamping rule was closed: SVG scripts inserted via innerHTML now get stamped too, so their copies are refused. The author notes that the technique still works in Safari 27.2.

Variants to test

  1. <selectedcontent> cloning in other sinks. Assign markup containing <select><selectedcontent></selectedcontent><option><svg><script>... to any DOM sink that parses HTML, not only innerHTML. A positive result is script execution from the cloned element, which you can confirm by alerting document.currentScript.parentNode.tagName and seeing SELECTEDCONTENT.
  2. Namespace checks. Take any working clone-based vector and remove <svg>, then remove <selectedcontent>. If execution stops in both cases, the target browser still has the namespace and cloning preconditions the author describes.
  3. Character-restricted contexts. Reuse the whitespace-free, slash-free, equals-free form <select><button><selectedcontent><button><option><svg><script>alert(1)<foo> where a filter blocks those characters. A positive result is an alert followed by the trailing page content being parsed as HTML rather than swallowed into the script.
  4. Sanitiser coverage. Run the payloads through any HTML sanitiser in front of the sink.
  5. Browser matrix. Test the same payload in each engine and version you care about. A positive result is execution in a browser that has not yet adopted the already started change for SVG scripts created via innerHTML.

Glossary

  • HTML: the language that describes the structure and content of a web page, such as headings, buttons and dropdown lists.
  • JavaScript: the programming language that runs inside a browser and makes pages interactive.
  • XSS (cross-site scripting): a bug where an attacker's text is treated by the browser as code written by the site, letting the attacker run JavaScript in someone else's browser.
  • innerHTML: a property that lets JavaScript read or replace the HTML inside an element; a common place where XSS happens.
  • Injection point: a place where text controlled by an attacker gets into a page or application.
  • Sink: the place in code where untrusted text is finally used in a way that can cause harm, such as an assignment to innerHTML.
  • Filter: code that inspects input and removes or blocks parts it considers dangerous.
  • DOM: the browser's internal tree-shaped model of a page, where every element is a node.
  • Node: one item in the DOM tree, such as an element or a piece of text.
  • Element: one HTML tag and its contents, such as a <select> or an <option>.
  • Attribute: a setting written inside a tag, such as selected on an <option>.
  • <select>: the HTML element for a dropdown list.
  • <option>: one choice inside a <select> dropdown.
  • <selectedcontent>: a newer HTML element that automatically copies the contents of the currently selected <option> into itself.
  • <svg>: the HTML element that introduces Scalable Vector Graphics, a way to describe drawings in markup.
  • Namespace: a label telling the browser which family of markup an element belongs to, such as HTML or SVG.
  • <script>: the HTML element that contains JavaScript for the browser to run.
  • alert(1): a tiny JavaScript program that shows a popup box; used as harmless proof that code ran.
  • document.currentScript: a built-in way for a running script to refer to itself.
  • parentNode: the element that contains a given node.
  • tagName: the name of an element's tag, such as SELECTEDCONTENT.
  • cloneNode(true): a built-in JavaScript function that makes a full copy of an element, including everything inside it.
  • append: a built-in JavaScript function that puts an element inside another element on the page.
  • Template literal: a way to write a string of text in JavaScript using backticks, which can contain line breaks and other characters conveniently.
  • Escape sequence: a way to write a special character in code using a backslash, such as \/ meaning /.
  • Specification (spec): the written rulebook that browser makers follow so pages behave consistently.
  • Already started flag: a true/false marker the browser keeps for each script element to record whether it has already been run, so it is not run twice.
  • Commit: a recorded change to a codebase, published so others can see what changed and why.
  • Chromium: the browser engine used by Chrome and several other browsers.
  • WebKit: the browser engine used by Safari.
  • Browser engine: the part of a browser that reads HTML and runs JavaScript.
  • DOMPurify: a popular JavaScript library that cleans HTML before it is put on a page, removing dangerous parts.
  • Bypass: input that gets past a filter or cleaner and still does something harmful.
  • Sanitiser: a tool that cleans HTML, such as DOMPurify.
  • Payload: the piece of text an attacker sends to try to trigger a bug.
  • Vector: the specific technique or payload used to carry out an attack.
  • Impossible lab: a deliberately hard practice challenge that was long believed to be unsolvable.
  • URL parameter: a value appended to a web address after a ?, used to pass information to a page.
  • URL encoding: writing special characters in a URL as % followed by codes, such as %3C for <.
  • Browser matrix: a list of browsers and versions to test against, so you know where something works and where it does not.

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.