Skip to content

fix: add output encoding in index.js (CWE-79) - #15798

Open
anupamme wants to merge 3 commits into
prebid:masterfrom
anupamme:fix-repo-prebid-js-cwe-79-bidviewabilitypixels-url-validation
Open

anupamme wants to merge 3 commits into
prebid:masterfrom
anupamme:fix-repo-prebid-js-cwe-79-bidviewabilitypixels-url-validation

Conversation

@anupamme

@anupamme anupamme commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Tighten JS viewability tracker URL validation in libraries/bidViewabilityPixels/index.js.

Changes

  • Trackers must parse as absolute http:/https: URLs with a host (new URL(url), no base URL).
  • Missing, empty, relative, protocol-relative, hostless, malformed and non-http(s) values are skipped; other valid trackers still fire.
  • The original URL string is emitted and still escaped with attributeValue() when building the iframe markup.
  • Regression tests added in test/spec/libraries/bidViewabilityPixels_spec.js.

Notes

The previous ^https?:// filter already rejected relative/missing URLs; this change additionally rejects hostless URLs such as https://. Output escaping (attributeValue) is the control against markup injection; validation and escaping address different risks.

Verification

  • npx gulp lint --files libraries/bidViewabilityPixels/index.js,test/spec/libraries/bidViewabilityPixels_spec.js --nolintfix: no output
  • npx gulp test-only --file test/spec/libraries/bidViewabilityPixels_spec.js: 27 passed (ChromeHeadless)
  • npx gulp test-only (full suite): all 8 chunks passed

Automated security fix generated by OrbisAI Security
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T01:34:15.521108Z 1d911c5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2893d6172b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread libraries/bidViewabilityPixels/index.js Outdated
@github-actions

Copy link
Copy Markdown

This PR introduces changes that may not work on all browsers. According to Babel, the following polyfills may be needed, and they are not automatically included:

  • Changes to libraries/bidViewabilityPixels/index.js may need:
    • web.url-search-params.delete
    • web.url-search-params.has
    • web.url-search-params.size

The best way to address this is to provide good test coverage, as normal PR checks run unit tests on older browsers.

Drop the window.location.href base so missing, empty, and relative
tracker URLs are no longer resolved to same-origin URLs. Trackers must
be absolute http(s) URLs with a host; the original string is still
escaped with attributeValue(). Adds regression tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@anupamme

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1d911c5a30

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread libraries/bidViewabilityPixels/index.js Outdated
Comment on lines +36 to +37
const { protocol, hostname } = new URL(url);
return (protocol === 'http:' || protocol === 'https:') && !!hostname;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require an authority before accepting HTTP tracker URLs

When a tracker is https:tracker.example/pixel (likewise https:/... or a backslash variant), the one-argument parser normalizes it to https://tracker.example/pixel, so this returns true, but the unnormalized input is emitted into the script tag. In the inserted about:blank iframe on an HTTPS publisher, the inherited base makes that same-scheme spelling resolve as a publisher-relative URL (for example, https://publisher.example/dir/tracker.example/pixel), producing a same-origin script request instead of the tracker; the old ^https?:// guard rejected it. Fresh evidence beyond the earlier removed-base case is this no-base-validation/original-string mismatch; require the // authority form as well or emit the parsed href.

Useful? React with 👍 / 👎.

@barecheck

barecheck Bot commented Oct 28, 2026

Copy link
Copy Markdown

Barecheck - Code coverage report

Total: 91.66%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@anupamme

Copy link
Copy Markdown
Contributor Author

✅ Review Feedback Addressed

I've automatically addressed 1 review comment(s):

Looking at the conversation history, there's a Codex review comment that identifies a security issue:

P2: Require an authority before accepting HTTP tracker URLs

When a tracker URL is https:tracker.example/pixel (or https:/... or a backslash variant), the one-argument new URL() parser normalizes it to https://tracker.example/pixel, so the validation passes. However, the original unnormalized string is still emitted into the script tag, which could be exploited.

The fix is to compare the normalized URL with the original input string. If they don't match, it means the URL parser had to fill in missing components (like adding // before the hostname), indicating a potentially malformed URL that should be rejected.

I'll update the isAbsoluteHttpUrl function to ensure the original string matches the normalized form.

Files modified:

  • libraries/bidViewabilityPixels/index.js

The changes have been pushed to this PR branch. Please review!

@github-actions

Copy link
Copy Markdown

Tread carefully! This PR adds 5 linter errors (possibly disabled through directives):

  • libraries/bidViewabilityPixels/index.js (+5 errors)

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.

2 participants