From c4ef7260ce2d3339caec5adce86e743cc31ba60e Mon Sep 17 00:00:00 2001 From: Claas Augner <495429+caugner@users.noreply.github.com> Date: Thu, 30 May 2024 05:17:13 +0200 Subject: [PATCH] fix(pong): avoid duplicate "https:" (#11212) --- libs/pong/pong2.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/libs/pong/pong2.js b/libs/pong/pong2.js index 320bb8041d32..b48aa3c8bb73 100644 --- a/libs/pong/pong2.js +++ b/libs/pong/pong2.js @@ -122,7 +122,7 @@ export function createPong2ClickHandler(coder) { } const anonymousIp = anonymousIpByCC(countryCode); - const clickURL = new URL(`https:${click}`); + const clickURL = createURL(click); clickURL.searchParams.set("forwardedip", anonymousIp); clickURL.searchParams.set("useragent", userAgent); @@ -140,7 +140,7 @@ export function createPong2ViewedHandler(coder) { const view = coder.decodeAndVerify(params.get("code")); if (view) { const anonymousIp = anonymousIpByCC(countryCode); - const viewURL = new URL(`https:${view}`); + const viewURL = createURL(view); viewURL.searchParams.set("forwardedip", anonymousIp); viewURL.searchParams.set("useragent", userAgent); @@ -150,3 +150,16 @@ export function createPong2ViewedHandler(coder) { } }; } + +function createURL(payload) { + if (payload.startsWith("//")) { + // BSA omitted 'https:' until May 2024. + return new URL(`https:${payload}`); + } + + if (!payload.startsWith("https://")) { + console.error(`Invalid URL payload: ${payload}`); + } + + return new URL(payload); +}