Skip to content

Fix: Decode double-encoded HTML entities in script/style attributes - #371

Closed
OlenaPostindustria wants to merge 3 commits into
prebid:masterfrom
postindustria-tech:fix/postscribe-script-src-amp-encoding
Closed

Fix: Decode double-encoded HTML entities in script/style attributes#371
OlenaPostindustria wants to merge 3 commits into
prebid:masterfrom
postindustria-tech:fix/postscribe-script-src-amp-encoding

Conversation

@OlenaPostindustria

Copy link
Copy Markdown
Contributor

Description

PUC 1.18.0 addressed Postscribe’s mishandling of single-quoted HTML attributes by re-serializing the adm through DOMParser before rendering. The HTML serializer correctly escapes & as &amp, within attribute values. However, this exposed a latent issue in Postscribe that caused impression callbacks loaded via <script src> to break.

Fix

Decode entities at the exact point postscribe diverges from browser behavior, using
postscribe's supported beforeWriteToken hook:

  • For script/style tokens only, decode entities in all attributes and in
    tok.src (postscribe copies attrs.src => tok.src before the hook runs, and
    assigns el.src = tok.src when building the element).
  • Static tokens are deliberately untouched - they're written through innerHTML
    where entities must stay encoded for the browser to decode.
  • Decoding round-trips the value through a real parsed attribute (DOMParser)
    instead of string replacement, so it matches browser attribute-decoding rules
    exactly: &amp; => &, while semicolon-less legacy references common in query
    strings (&notify=, &copy=) stay literal, as they would in a real browser.

Also hardens normalizeMarkup: a marker element forces the parser into body mode so
leading comments (e.g. Prebid's <!--Creative served by ...-->) and head-bound
elements are preserved in order instead of being dropped or scattered into <head>.

Screenshot 2026-08-05 at 15 05 14 Screenshot 2026-08-05 at 15 05 51

@OlenaPostindustria
OlenaPostindustria marked this pull request as draft August 7, 2026 09:34
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