Injection in CSS (CVE-2026-79234)
Blink's CSSOM serialisation of syntax components fails to escape identifier tokens, so an attacker can use CSS escape sequences to smuggle metacharacters into a parsed identifier. When the stylesheet is re-serialised via cssText, those metacharacters break out of the @function or @mixin rule and inject arbitrary top-level CSS rules.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 3 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 CSSOM serialization in Blink potentially fails to escape identifier tokens in CSSSyntaxComponent::ToString(), outputting raw decoded characters instead of using SerializeIdentifier(). This can allow an attacker to use CSS escape sequences to construct a parsed identifier containing metacharacters like parentheses or braces, which when serialized via cssText, could break out of the rule block and inject arbitrary top-level CSS rules.
Affected files:
third_party/blink/renderer/core/css/css_syntax_component.hthird_party/blink/renderer/core/css/css_syntax_definition.ccthird_party/blink/renderer/core/css/css_function_rule.ccthird_party/blink/renderer/core/css/css_mixin_rule.ccthird_party/blink/renderer/core/css/css_syntax_string_parser.cc
Estimated timestamp from git blame: 2024-10-28
Potential CSSOM Rule Injection via Missing Identifier Serialization in CSSSyntaxComponent::ToString
Root Cause
In third_party/blink/renderer/core/css/css_syntax_component.h, CSSSyntaxComponent::ToString() is used during serialization to serialize individual components of a syntax definition. When the component's type is CSSSyntaxType::kIdent, it directly returns the string_ member verbatim instead of applying the standard CSSOM identifier serialization algorithm:
String ToString() const {
String result =
(type_ == CSSSyntaxType::kIdent) ? string_ : blink::ToString(type_);
return StrCat({result, blink::ToString(repeat_)});
}
The correct primitive to use is SerializeIdentifier(), implemented in third_party/blink/renderer/core/css/css_markup.cc, which escapes non-name code points and metacharacters. Since raw decoded strings are emitted directly into the serialized text, this breaks the invariant parse(serialize(x)) == x.
Why string_ Can Contain CSS Metacharacters
When parsing CSS, the tokenizer decodes escape sequences during the construction of an identifier. For example, ConsumeName() unconditionally appends decoded characters parsed via ConsumeEscape() in third_party/blink/renderer/core/css/parser/css_parser_idioms.cc. Therefore, an input identifier containing escaped metacharacters like a\\29 b is tokenized into a single identifier token with a decoded value of a)b.
This decoded value is stored directly in the <syntax> definition string or component via CSSSyntaxDefinition::Consume() or the string parser path in css_syntax_string_parser.cc.
Potential Sinks
Serialized CSS syntax components are used during the serialization of @function and @mixin rules. Specifically, CSSFunctionRule::cssText() embeds CSSSyntaxDefinition::ToString() into the rule-prelude CSS text via AppendCSSType():
void AppendCSSType(const CSSSyntaxDefinition& syntax, StringBuilder& builder) {
CHECK(!syntax.IsUniversal());
bool wrap_in_type = syntax.Components().size() != 1u;
if (wrap_in_type) { builder.Append("type("); }
builder.Append(syntax.ToString()); // <-- Raw decoded identifier lands here
if (wrap_in_type) { builder.Append(")"); }
}
This function is called when serializing both parameter types and return types of @function and @mixin rules. Because the @function feature (CSSFunctions) is stable and enabled by default, this code path is fully web-reachable without flags.
Potential Impact
Because of this serialization flaw, an attacker could potentially construct a stylesheet containing escaped characters that parse safely as a single identifier. When that stylesheet is subsequently serialized via rule.cssText (a common behavior in client-side or CSSOM-based HTML/CSS sanitizers that re-serialize parsed sheets), the output will contain unescaped metacharacters. This can break out of the @function or @mixin rule context and insert arbitrary new top-level rules (such as arbitrary style rules with exfiltration url() beacons, @keyframes, or @font-face definitions) that the sanitizer never validated.
Note: The following steps and proof of concept are potential vectors. Our tooling agent does not have the capability to run code to confirm execution in a live browser.
Potential Steps to Reproduce / Proof of Concept
If the following script is executed in the browser:
const s = new CSSStyleSheet();
s.replaceSync(
'@function --f(--p a\\29 \\7B \\7D \\2A\\7B background\\3A url\\28\\2F\\2F evil\\2F\\29\\7D x) { result: 1px; }'
);
console.log(s.cssRules[0].cssText);
Observed Output:
@function --f(--p a){}*{background:url(//evil/)}x) { result: 1px; }
When re-serialized, the string contains an unescaped closing parenthesis and braces that close the @function block early, inserting *{background:url(//evil/)} as a brand new top-level style rule.
Suggested Fix
To fix this vulnerability, CSSSyntaxComponent::ToString() should serialize identifiers using SerializeIdentifier when type_ == CSSSyntaxType::kIdent:
String ToString() const {
String result;
if (type_ == CSSSyntaxType::kIdent) {
StringBuilder builder;
SerializeIdentifier(string_, builder);
result = builder.ReleaseString();
} else {
result = blink::ToString(type_);
}
return StrCat({result, blink::ToString(repeat_)});
}
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.
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 CSSSyntaxComponent::ToString() returns the decoded identifier string verbatim instead of applying the standard CSSOM identifier serialisation algorithm, breaking the parse(serialize(x)) == x invariant.
Impact
An attacker could potentially inject arbitrary top-level CSS rules, such as style rules with exfiltration url() beacons, @keyframes, or @font-face definitions, into output that a CSSOM-based sanitizer never validated; the report notes the tooling did not confirm execution in a live browser.
What the attacker needed
Victim loads attacker-controlled CSS; CSS is re-serialised by a sanitizer; Chrome with @function enabled
The fix
CSSSyntaxComponent::ToString() should serialise identifiers using SerializeIdentifier when the component type is kIdent.
How it was found
- Create a CSSStyleSheet and replace its contents with a stylesheet containing an @function rule whose parameter type uses CSS escape sequences for metacharacters.
- Read back the first rule's cssText property.
- Observe that the serialised output contains unescaped parentheses and braces that close the @function block early and insert a new top-level style rule.
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 can decode escape sequences such as backslash codes into ordinary characters. If the browser later writes that CSS back out without re-escaping those characters, a crafted stylesheet can contain characters like braces or parentheses that were meant to be harmless data. A sanitizer that trusts the re-serialised output could then be tricked into allowing new CSS rules it never checked.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.