Skip to content

Prevent double-escaping of HTML-encoded ampersands in createTrackPixelHtml and add tests - #15327

Merged
patmmccann merged 2 commits into
codex/fix-unsanitized-nurl-tracking-pixel-security-issuefrom
codex/fix-double-escaping-of-html-encoded-urls
Jul 8, 2026
Merged

Prevent double-escaping of HTML-encoded ampersands in createTrackPixelHtml and add tests#15327
patmmccann merged 2 commits into
codex/fix-unsanitized-nurl-tracking-pixel-security-issuefrom
codex/fix-double-escaping-of-html-encoded-urls

Conversation

@patmmccann

Copy link
Copy Markdown
Collaborator

Motivation

  • Ensure query separators that are already HTML-encoded (like &, &, &) are not double-escaped when building a tracking pixel img src attribute, which can produce incorrect URLs or broken attributes.
  • Add unit tests to assert the correct handling of various encoded ampersand forms.

Description

  • Add a helper decodeAmpersandEntities that converts &, &, and & to the literal & before further processing.
  • Update createTrackPixelHtml to call decodeAmpersandEntities(url) before applying the provided encode function and HTML-escaping, preventing double-encoding of already-encoded separators.
  • Extend test/spec/utils_spec.js with cases verifying that createTrackPixelHtml preserves or normalizes encoded query separators and does not double-escape them.
  • Minor test formatting adjustments in the encodeMacroURI test block for consistency.

Testing

  • Ran the unit test suite which includes the updated test/spec/utils_spec.js specs; the tests covering createTrackPixelHtml and encodeMacroURI passed.
  • The new cases asserting handling of &, &, and & were executed as part of the automated tests and succeeded.

Codex Task

### Motivation
- Tracker image URLs coming from ad markup or XML can already contain HTML-entity encoded separators like `&`, and passing them through the existing encode+escape path produced `&` in emitted HTML which breaks server-side parameter parsing.

### Description
- Add a small helper `decodeAmpersandEntities(url)` that converts existing `&` back to `&` before encoding.
- Normalize URLs by calling `encode(decodeAmpersandEntities(url))` inside `createTrackPixelHtml` so already-encoded query separators are not double-escaped.
- Add a unit test in `test/spec/utils_spec.js` that asserts `createTrackPixelHtml` preserves `&` separators in emitted `src` for an input URL containing `&`.
- Fix nearby missing semicolons in `test/spec/utils_spec.js` to satisfy linting for the changed file.

### Testing
- Ran lint on the changed files with `npx eslint src/utils.js test/spec/utils_spec.js --cache --cache-strategy content` and it passed for the final change set.
- Ran the targeted unit tests with `npx gulp test --nolint --file test/spec/utils_spec.js` and the test chunk completed successfully (`185 tests completed`).
…e' into codex/fix-double-escaping-of-html-encoded-urls
@patmmccann
patmmccann merged commit 87ce655 into codex/fix-unsanitized-nurl-tracking-pixel-security-issue Jul 8, 2026
5 checks passed
@patmmccann
patmmccann deleted the codex/fix-double-escaping-of-html-encoded-urls branch July 8, 2026 11:34
patmmccann added a commit that referenced this pull request Jul 28, 2026
…15049)

* Core: escape tracking pixel URLs in HTML attributes

* Core: avoid double-escaping tracker query separators (#15325)

* Core: avoid double-escaping tracker query separators (#15327)

### Motivation
- Tracker image URLs coming from ad markup or XML can already contain HTML-entity encoded separators like `&`, and passing them through the existing encode+escape path produced `&` in emitted HTML which breaks server-side parameter parsing.

### Description
- Add a small helper `decodeAmpersandEntities(url)` that converts existing `&` back to `&` before encoding.
- Normalize URLs by calling `encode(decodeAmpersandEntities(url))` inside `createTrackPixelHtml` so already-encoded query separators are not double-escaped.
- Add a unit test in `test/spec/utils_spec.js` that asserts `createTrackPixelHtml` preserves `&` separators in emitted `src` for an input URL containing `&`.
- Fix nearby missing semicolons in `test/spec/utils_spec.js` to satisfy linting for the changed file.

### Testing
- Ran lint on the changed files with `npx eslint src/utils.js test/spec/utils_spec.js --cache --cache-strategy content` and it passed for the final change set.
- Ran the targeted unit tests with `npx gulp test --nolint --file test/spec/utils_spec.js` and the test chunk completed successfully (`185 tests completed`).

* Kimberlite Bid Adapter: fix nurl pixel test expectation (#15338)

* TrustX Bid Adapter: fix tracking URL test assertion (#15337)

* Adkernel Bid Adapter: fix banner nurl pixel test (#15339)

* Core: preserve tracking pixel URL behavior (#15390)

---------

Co-authored-by: Demetrio Girardi <dgirardi@prebid.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant