Medium

PostCSS has XSS via Unescaped </style> in its CSS Stringify Output

  • Disclosed: 24.04.2026
  • Updated: 11.10.2026 10:22

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

js
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:

js
output = output.replace(/<\/(style)/gi, '<\\/$1');

Credits

Discovered and reported by Sunil Kumar (@TharVid)

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
npm package postcss < 8.5.10 8.5.10

References

CVSS score 6.1/10
CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
Weakness (CWE)
CWE-79
Platform
npm
Package
postcss
Disclosed
24.04.2026
Updated
11.10.2026 10:22

Sources and licenses

OSV / GitHub Advisory Database - GHSA-qx2v-qp2m-jg93 - CC BY 4.0

Vulnerability history: postcss

All published vulnerabilities of this package (npm package), newest first. Shows whether this is a one-off slip or a package that needs watching.

Total entries
7
First → latest
05.2021 08.2026
Without a fix
0
Exploited in attacks
0

Severity breakdown

  • High 2
  • Medium 5

Disclosures per year

  1. 2021: 1
  2. 2022: 1
  3. 2023: 1
  4. 2024: 0
  5. 2025: 0
  6. 2026: 4
  1. PostCSS has XSS via Unescaped </style> in its CSS Stringify Output this entry
    Medium · 6.1 CVE-2026-41305 < 8.5.10 8.5.10
  2. Medium · 5.3 CVE-2023-44270 < 8.4.31 8.4.31
  3. Medium · 5.3 CVE-2021-23382 >= 8.0.0, < 8.2.13, < 7.0.36 8.2.13, 7.0.36
  4. Medium · 5.3 CVE-2021-23368 >= 7.0.0, < 7.0.36, >= 8.0.0, < 8.2.10 7.0.36, 8.2.10

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.