Skip to content

fix: escape markup in inlined pseudo-element content - #707

Merged
cossssmin merged 1 commit into
masterfrom
fix/escape-pseudo-element-content
Nov 10, 2026
Merged

cossssmin merged 1 commit into
masterfrom
fix/escape-pseudo-element-content

Conversation

@cossssmin

Copy link
Copy Markdown
Collaborator

Fixes GHSA-pfw7-6c5v-2837.

With inlinePseudoElements: true, the CSS content value of ::before/::after rules was inserted into the output as raw HTML. Juice parses with decodeEntities: false, so .text() is serialized unescaped, and markup in content strings, attr() or var() values became live HTML:

juice('<style>b:after{content:"<svg onload=alert(1)>"}</style><b>x</b>', { inlinePseudoElements: true })
// before: <b>x<span><svg onload=alert(1)></span></b>
// after:  <b>x<span>&lt;svg onload=alert(1)&gt;</span></b>

Changes

  • Escape < and > in pseudo-element text when the cheerio instance writes text raw. & is left alone, so entities like &nbsp; keep working and attr() values aren't double-escaped.
  • Whether the instance writes raw text is probed once per call with cheerio's public API, so cheerio instances passed to juiceDocument/inlineDocument with default options (which already escape) aren't double-escaped.

Behavior change

Only affects inlinePseudoElements: true. Tags inside CSS content (e.g. content: "<br>") now render as literal text, matching how browsers treat content. Regular HTML in the email is untouched.

Tests

Regression tests for content strings, attr(), xmlMode, entity preservation, and a default cheerio instance via inlineDocument.

🤖 Generated with Claude Code

With inlinePseudoElements enabled, the CSS content value of ::before and
::after rules was written into the output unescaped, because juice
parses with decodeEntities off and .text() is then serialized raw. Markup
in content strings, attr() or var() values became live HTML.

Escape < and > when the cheerio instance writes text raw, and leave text
alone for instances that already escape it, to avoid double escaping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cossssmin
cossssmin merged commit 7610306 into master Nov 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant