Skip to content
XSS Write-up Advanced

DOM-based race condition: racing in the browser for fun

A DOM-based race condition allows an attacker to execute XSS by tricking a victim into pasting malicious content into a contenteditable element before a JavaScript library (like AngularJS) loads and processes it. The attacker can extend the race window by exhausting the browser's connection pool, delaying the library load.

ryotak Follow

Published on blog.ryotak.net

All projects mentioned in this blog post have been contacted, and I confirmed that the behavior described in this article is either working as intended, already fixed, or will not be fixed.

RyotaK, on blog.ryotak.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.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the library processes DOM elements after page load without ignoring content inside contenteditable elements, allowing attacker-controlled pasted content to be evaluated.

Impact

An attacker could execute arbitrary JavaScript in the victim's browser, potentially stealing data or performing actions on behalf of the user.

What the attacker needed

Victim pastes into contenteditable; library loads after contenteditable; attacker can exhaust connection pool

The fix

Libraries should ignore elements inside contenteditable or not process DOM after load; developers should avoid using contenteditable with such libraries.

How it was found

  1. Exhaust the browser's connection pool by opening many connections that won't be closed.
  2. Open the victim page, which will be delayed due to the exhausted pool.
  3. Cancel one connection and quickly open another to allow the victim page to load while keeping the pool exhausted.
  4. The victim page's contenteditable element is rendered, and the library script is queued but not loaded.
  5. Trick the victim into pasting malicious content into the contenteditable element.
  6. After a delay, cancel the connection to allow the library to load and evaluate the pasted content, executing the payload.

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 write-up has not been written yet. The Original tab links to the source.

When a web page loads, the browser reads the HTML from top to bottom. Some JavaScript libraries wait until the page is fully loaded before they look at the content and act on it. If a user can paste something into an editable area before the library runs, the library might treat the pasted content as trusted and execute it, leading to cross-site scripting (XSS).

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 ryotak

View all

6 more disclosed reports, best first.

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.