Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting Query String doesn't properly encode #10514

Closed
JoshuaRogan opened this issue Sep 21, 2023 · 5 comments
Closed

Formatting Query String doesn't properly encode #10514

JoshuaRogan opened this issue Sep 21, 2023 · 5 comments
Labels

Comments

@JoshuaRogan
Copy link

JoshuaRogan commented Sep 21, 2023

Type of issue

Bug

Description

One of the two functions that can format a query string doesn't correctly encode values.

Two format Functions:
https://github.com/prebid/Prebid.js/blob/master/src/utils.js#L135
https://github.com/prebid/Prebid.js/blob/master/src/utils.js#L1165 --> Doesn't properly encode

Steps to reproduce

Input any URL with query params into this function as an input.

(See test page for more reproduction steps)

Test page

CodePen Extracted Example

https://codepen.io/Josh-Rogan/pen/bGOaMWr?editors=0012

In the following code pen, when a query param contains something similar to a URL with query params, it won't properly encode those into the final string. Looking at the console output description_url is not properly parsed.

Intermittent Live Test Page

This only works sometimes so may not be the best way to reproduce

Live Test Page

Use network tab to find gampad/ads? and sometimes you can see where you end up with additional query params like cust_params which are not properly within it's variable

Expected results

All query params are properly encoded.

Actual results

All query params are not encoded. In particular, if any query param value has a & it will pollute the real query params with additional query params.

Platform details

  • Chrome but this can reproduced in any environment

Other information

Ideally, we should not be using multiple query string formatting functions. This would be a good opportunity to unify and potentially update to use URLSearchParams(https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)

Quick Fix

@dgirardi
Copy link
Collaborator

I agree that some refactoring is warranted, but unfortunately the "wrong" version is used in many places, with many callers assuming they need to do the encoding themselves - so it cannot be simply "fixed" and I'm not sure we want to try to refactor everything (you cannot always tell from the code whether the inputs are already URL-encoded).

Do you have more details on where specifically this is a problem? Could it be fixed by switching to the alternate version?

@dgirardi
Copy link
Collaborator

This might be one:

return buildUrl(Object.assign({
protocol: 'https',
host: 'securepubads.g.doubleclick.net',
pathname: '/gampad/ads'
}, urlComponents, { search: queryParams }));

@lcorrigall lcorrigall moved this from Triage to Needs OP in Prebid.js Tactical Issues table Sep 25, 2023
@dgirardi
Copy link
Collaborator

I am not able to spot the issue from the demo page - but I'm not sure what I'm looking for. The code appears to know that it should encode cust_params:

let encodedCustomParams = getCustParams(bid, options, urlSearchComponent && urlSearchComponent.cust_params);

@patmmccann
Copy link
Collaborator

Flagging jwplayer#59 as a possible 9.0 change to debate

@patmmccann patmmccann moved this from Needs OP to Blocked in Prebid.js Tactical Issues table Dec 4, 2023
@patmmccann
Copy link
Collaborator

Committee decided not to change the utility without changing all the places it was used to reflect new behavior. We're not actively planning to take on the larger scoped project as the utility is in widespread use.

@patmmccann patmmccann closed this as not planned Won't fix, can't repro, duplicate, stale May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

4 participants