Skip to content
XSS Advisory Advanced CVE-2026-17845

Inappropriate implementation in CSS (CVE-2026-17845)

Blink's media query serialisation fails to escape the media type when a conditional expression is present, so escaped characters that decode into CSS metacharacters are emitted raw. If an application reads the serialised CSS and re-injects it, an attacker could inject arbitrary CSS rules.

Google Chrome

Originally disclosed on Chrome VRP

  • Fix shipped in 2 months

Project Fortify, an experimental security project, has identified the following potential security issue. If you're a feature owner CC-ed on this bug, please do your best to review these reports. Please see https://chromium.googlesource.com/chromium/src/+/main/docs/security/ai-generated-security-bugs-faq.md for more information.

Overview: The serialization logic in MediaQuery::Serialize fails to escape media types when serializing a media query that has a conditional expression. An attacker can construct a media type containing escaped characters that decode into CSS metacharacters, which are then output raw during serialization. If a web application parses, serializes, and subsequently re-injects the resulting CSS, this can lead to arbitrary CSS injection.

Affected files:

  • third_party/blink/renderer/core/css/media_query.cc
  • third_party/blink/renderer/core/css/parser/media_query_parser.cc

Estimated timestamp from git blame: 2026-03-30

Summary

A potential vulnerability has been identified in Blink's CSSOM serialization logic. When a media query contains both a media type and a conditional expression node (e.g., <type> and <condition>), MediaQuery::Serialize() fails to escape the media type string. This allows decoded, unescaped identifier strings containing CSS metacharacters (such as { or }) to be serialized raw. If a web application retrieves the serialized text and later re-injects it (such as inside a client-side sanitizer, dynamic style modifier, or CSSOM-to-CSS generator), it can lead to arbitrary CSS injection and Mutation XSS (mXSS).

Root Cause

In third_party/blink/renderer/core/css/media_query.cc, the MediaQuery::Serialize() method has two branches to output the media type:

  1. When exp_node == nullptr: The media type is correctly escaped using SerializeIdentifier (line 59).
  2. When exp_node != nullptr: The unescaped MediaType() is appended directly to the output string builder using raw result.Append() (line 65).
C++
// third_party/blink/renderer/core/css/media_query.cc
const ConditionalExpNode* exp_node = ExpNode();

if (!exp_node) {
  SerializeIdentifier(MediaType(), result);   // Escaped correctly
  return result.ReleaseString();
}

if (MediaType() != media_type_names::kAll ||
    Restrictor() != RestrictorType::kNone) {
  result.Append(MediaType());                 // <--- Unescaped raw append
  result.Append(" and ");
}

When parsing the initial CSS rule, the tokenizer decodes escape sequences. An identifier token specified as \7d\2a\7b\63olor\3a\72\65\64\7d decodes into the literal string }*{color:red}. This bypasses initial restriction checks because it is parsed as a single identifier token. However, because the serialization phase lacks the corresponding escaping logic for the conditional branch, the literal } and { characters are serialized raw into the CSSOM output.

Potential Impact

If a web application reads the serialized rule (cssText, mediaText, or conditionText) and re-injects it (e.g., using CSSStyleSheet.replaceSync() or direct stylesheet modification), the literal } character closes the existing media rule block prematurely. Any trailing characters will then be parsed as a new top-level style rule, allowing arbitrary CSS injection. While this does not cause memory corruption, it can lead to UI spoofing or data exfiltration via attribute-selector and background-image side channels in affected applications.

Suggested Reproduction Steps

(Note: These are potential steps based on source code analysis; our tooling has not run this code to verify).

  1. Parse a stylesheet containing escaped characters in a conditional media query:

    JavaScript
    const s = new CSSStyleSheet();
    s.replaceSync('@media \\7d\\2a\\7b\\63olor\\3a\\72\\65\\64\\7d and (color){}');
    
  2. Retrieve the serialized text:

    JavaScript
    const serialized = s.cssRules[0].cssText;
    // The expected output should contain a properly escaped identifier.
    // Instead, the potential output contains the unescaped literal `}*{color:red} and (color)`.
    
  3. Re-inject the serialized CSS:

    JavaScript
    otherSheet.replaceSync('body{}' + serialized);
    // The unescaped `}` closes the first rule prematurely, and `*{color:red}` is parsed as a top-level universal rule.
    

Recommended Fix

Ensure that the media type is serialized using SerializeIdentifier in all branches of MediaQuery::Serialize().

C++
// third_party/blink/renderer/core/css/media_query.cc
if (MediaType() != media_type_names::kAll ||
    Restrictor() != RestrictorType::kNone) {
  SerializeIdentifier(MediaType(), result);
  result.Append(" and ");
}

Evaluated with Chrome root at commit: fb72408a8493c46bc75fae1c70d03daec96b3040


Results so far have been promising, but there can be wrong deductions. Feel free to adjust as follows:

  • If you are familiar with the severity guidelines, you may adjust the severity.
  • If this is a false positive, and there's no work to be done, please close as WAI.
  • If there is work to do here but not a vulnerability, please change the issue type to Task/Bug/FR.

Data from false positives will be used to improve accuracy over time. And please feel free to reach out to me directly if you have concerns or feedback on the project.

The original report as published on the Chromium issue tracker. Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

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

In the branch where a conditional expression node exists, MediaQuery::Serialize appends the media type with a raw string append instead of using SerializeIdentifier, so decoded metacharacters are not re-escaped.

Impact

If an application re-injects the serialised rule, a closing brace could end the media block early and trailing text could be parsed as a new top-level rule, potentially enabling UI spoofing or data exfiltration; the report notes this does not cause memory corruption.

What the attacker needed

Application re-injects serialised CSS; attacker controls CSS input

The fix

The media type should be serialised with SerializeIdentifier in every branch of MediaQuery::Serialize().

How it was found

  1. Parse a stylesheet containing escaped characters in a conditional media query.
  2. Read back the serialised cssText of the rule.
  3. Re-inject the serialised CSS into another stylesheet.

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 a browser reads CSS it sometimes writes it back out as text. Here it writes a piece of the media query without protecting special characters like curly brackets. If a website takes that text and puts it back into a stylesheet, the brackets can break out of the intended rule and add new styling the site did not want.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More from Google Chrome

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.