CVE-2026-41305: PostCSS has XSS via Unescaped </style> in its CSS Stringify Output
PostCSS: XSS via Unescaped </style> in CSS Stringify Output
Summary
PostCSS v8.5.5 (latest) does not escape </style> sequences when stringifying CSS ASTs. When user-submitted CSS is parsed and re-stringified for embedding in HTML <style> tags, </style> in CSS values breaks out of the style context, enabling XSS.
Proof of Concept
javascript const postcss = require('postcss');
// Parse user CSS and re-stringify for page embedding const userCSS = 'body { content: "</style><script>alert(1)</script><style>"; }'; const ast = postcss.parse(userCSS); const output = ast.toResult().css; const html = <style>${output}</style>;
console.log(html); // <style>body { content: "</style><script>alert(1)</script><style>"; }</style> // // Browser: </style> closes the style tag, <script> executes
Tested output (Node.js v22, postcss v8.5.5): Input: body { content: "</style><script>alert(1)</script><style>"; } Output: body { content: "</style><script>alert(1)</script><style>"; } Contains </style>: true
Impact
Impact non-bundler use cases since bundlers for XSS on their own. Requires some PostCSS plugin to have malware code, which can inject XSS to website.
Suggested Fix
Escape </style in all stringified output values: javascript output = output.replace(/<\/(style)/gi, '<\\/$1');
Credits Discovered and reported by Sunil Kumar (@TharVid)
Other sources
PostCSS takes a CSS file and provides an API to analyze and modify its rules by transforming the rules into an Abstract Syntax Tree. Versions prior to 8.5.10 do not escape /style sequences when stringifying CSS ASTs. When user-submitted CSS is parsed and re-stringified for embedding in HTML style tags, /style in CSS values breaks out of the style context, enabling XSS. Version 8.5.10 fixes the issue.
— IBM
PostCSS takes a CSS file and provides an API to analyze and modify its rules by transforming the rules into an Abstract Syntax Tree. Versions prior to 8.5.10 do not escape </style> sequences when stringifying CSS ASTs. When user-submitted CSS is parsed and re-stringified for embedding in HTML <style> tags, </style> in CSS values breaks out of the style context, enabling XSS. Version 8.5.10 fixes the issue.
— NVD
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
npm/postcssto a version that resolves this vulnerability.Fixed in 8.5.10 - Upgrade
Upgrade
postcssto a version that resolves this vulnerability.Fixed in 8.5.10 - Configuration
Ensure the PostCSS CSS stringification step escapes `</style` sequences (and effectively `/style` sequences) in all stringified output values before embedding in an HTML `<style>` tag.
PostCSS CSS stringification output Escape closing style sequences (`</style` / `</style>` and `/style` in stringified values) = Escape `</style` sequences in all stringified output values
Event History
Frequently Asked Questions
What is the severity of CVE-2026-41305?
CVE-2026-41305 is classified as a Cross-Site Scripting (XSS) vulnerability that could lead to serious security issues in web applications.
How do I fix CVE-2026-41305?
To fix CVE-2026-41305, upgrade PostCSS to version 8.5.10 or later.
What software is affected by CVE-2026-41305?
CVE-2026-41305 affects PostCSS versions prior to 8.5.10.
What type of vulnerability is CVE-2026-41305?
CVE-2026-41305 is an XSS vulnerability caused by unescaped </style> sequences in CSS Stringify Output.
How does CVE-2026-41305 impact web applications?
CVE-2026-41305 allows attackers to execute arbitrary scripts in the context of the user in affected web applications.