Repository navigation
Escape </style> in output of non-Root nodes (follow-up to 7f5c417) - #2163
Conversation
Since the escaping moved to SafeStringifier, only Root output was escaped. Rule, AtRule, Declaration and Comment returned raw </style> and <!-- from toString() and postcss.stringify(), which 8.5.28 still escaped.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe default stringifier now applies HTML escaping to non-root and non-document nodes. Tests cover escaping of style-closing tags and comments across several node types. ChangesStringifier escaping
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The escaping change has no established merge-blocking issue; it is ready for normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change strengthens default serialization without an identified weakening of existing controls. Remaining uncertainty concerns how applications supply untrusted CSS and embed the resulting output into HTML. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| if (node.type === 'root' || node.type === 'document') { | ||
| str.stringify(node) | ||
| } else { | ||
| str.escapeHTML(node, () => str.stringify(node)) |
There was a problem hiding this comment.
Can you explain why it is the best place to put escape?
Why not Node#toString for instance?
There was a problem hiding this comment.
Node#toString() actually calls this same stringify() function internally, it's the default: toString(stringifier = stringify). And postcss.stringify(node, builder) is also exported directly as its own public API, used independently of toString() (lib/no-work-result.js and lib/lazy-result.js both import it directly too).
If I escaped in toString() instead, a direct call to postcss.stringify(node, builder). which is exactly one of the bypass cases in the original report would stay unescaped, since it never goes through toString() at all. Putting it here covers both entry points with one change, which is also where the existing root() escaping already lives, so it keeps all the escaping logic in one file instead of split across two.
I hope this explaination helps!
Port of upstream "Escape </style> in output of non-Root nodes (postcss#2163)", which repairs the SafeStringifier escaping of the previous commit. Upstream-Commit: 7647a81 Co-authored-by: Choudhry Shehryar <[email protected]>
Summary
Follow-up to GHSA-xcmx-fw7g-g937: 7f5c417 moved the
</style>escaping from GHSA-qx2v-qp2m-jg93 intoSafeStringifier, but the only override there isroot().Node#toString()andpostcss.stringify()on aRule,AtRule,DeclarationorCommentgo straight to the plainStringifiermethods, so they come out unescaped again. 8.5.28 escapes these; this is a regression onmain, not released yet.As discussed in the advisory thread, this isn't a security issue on its own — nothing released is affected, and there's no realistic case for calling
node.toString()to build an HTML document directly. This PR just restores the output consistency that existed in 8.5.10–8.5.28: all node types get the same</style>/<!--escaping, not justRoot.Changes
stringify()now wraps every top-level node that isn't aRootorDocumentin the existingescapeHTML(), matching whatroot()already does, including the split-payload case inside a rule's raws.Tests
Added cases next to the existing GHSA-qx2v-qp2m-jg93 tests covering each node type (
Rule,AtRule,Declaration,Comment), a detachedDeclaration, andpostcss.stringify()with a custom builder. Renamed"escapes only Root output of the default stringifier"to"escapes only output of the default stringifier"since its assertion didn't actually test Root-only behavior. Fullpnpm testpasses (719 tests: coverage, lint, types, size, integration).Summary by CodeRabbit