Inappropriate implementation in CSS (CVE-2026-17827)
The CSS serialization in Blink fails to escape custom property names when serializing style container queries, allowing an attacker to inject unescaped CSS rules. This breaks the CSSOM round-trip invariant and could enable CSS mutation XSS in sanitizers and downstream parsers.
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 CSS serialization mechanism in Blink fails to escape custom property names when serializing style container queries, resulting in unescaped rule injection in the CSSOM. An attacker can craft a style query containing escaped characters that parses as a single valid rule but serializes into multiple top-level rules. This breaks the CSSOM round-trip invariant, potentially enabling CSS mutation XSS (CSS-mXSS) in sanitizers and downstream parsers.
Affected files:
third_party/blink/renderer/core/css/media_query_exp.cc
Estimated timestamp from git blame: 2022-06-24
Root Cause
In third_party/blink/renderer/core/css/media_query_exp.cc, the MediaQueryExp::Serialize() function appends the stored feature name (media_feature_) verbatim to the output string builder without applying the CSSOM's serialize an identifier algorithm:
String MediaQueryExp::Serialize() const {
StringBuilder result;
if (!bounds_.IsRange()) {
if (HasMediaFeature() || IsCustomMedia()) {
result.Append(media_feature_); // Raw append without escaping
}
}
return result.ReleaseString();
}
For style queries, the custom property parsed is processed by StyleFeatureSet, whose only restriction is starting with --. During parsing, escape sequences (e.g., closing brackets or braces) are decoded into raw characters and stored. Upon serialization through web-exposed entry points like CSSContainerRule::cssText(), these stored characters are output unescaped, leading to structural rule injection.
Potential Attack Steps
An attacker can define a style query containing escaped characters that decode to braces and rule-ending delimiters. When serialized, these characters are written raw into the output. For example, a style container query like --a followed by braces and raw CSS will serialize directly, resulting in injected CSS rules. Any downstream sanitizer that parses and then serializes this CSSOM tree will emit rule-injected CSS, bypassing sanitization filters.
Suggested Fix
Import third_party/blink/renderer/core/css/css_markup.h and use SerializeIdentifier(media_feature_, result) instead of result.Append(media_feature_) inside MediaQueryExp::Serialize().
Evaluated with Chrome root at commit: 5133b93d189b383c37805b1cf3a9d2dbfe8d7379
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.
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 MediaQueryExp::Serialize() function appends the stored feature name directly without applying the CSSOM's serialize an identifier algorithm, so escaped characters are output raw.
Impact
This could enable CSS mutation XSS in sanitizers and downstream parsers, potentially allowing script execution if the injected CSS is used in a context where it can execute code.
What the attacker needed
Attacker can inject CSS with escaped characters; downstream sanitizer parses and serializes CSSOM
The fix
The suggested fix is to import css_markup.h and use SerializeIdentifier(media_feature_, result) instead of result.Append(media_feature_) inside MediaQueryExp::Serialize().
How it was found
- An attacker defines a style query containing escaped characters that decode to braces and rule-ending delimiters.
- When the style query is serialized, these characters are written raw into the output.
- A downstream sanitizer that parses and then serializes this CSSOM tree emits rule-injected CSS, bypassing sanitization filters.
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 web browser reads CSS code, it sometimes needs to write it back out as text. This report says that in one specific case, the browser writes out a custom property name without escaping special characters, so an attacker can sneak in extra CSS rules. That could trick security filters that clean CSS into letting harmful code through.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.