From b5102d87ae3e0679a93838ab870ca0d202602a1a Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Thu, 14 Dec 2023 18:33:44 +0100 Subject: [PATCH] chore(pong): pass anonymous ip on click request --- cloud-function/src/handlers/proxy-bsa.ts | 2 +- libs/pong/pong2.d.ts | 3 ++- libs/pong/pong2.js | 11 +++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cloud-function/src/handlers/proxy-bsa.ts b/cloud-function/src/handlers/proxy-bsa.ts index bfa752d511c7..4f8e6436e66f 100644 --- a/cloud-function/src/handlers/proxy-bsa.ts +++ b/cloud-function/src/handlers/proxy-bsa.ts @@ -53,7 +53,7 @@ export async function proxyBSA(req: Request, res: Response) { } const params = new URLSearchParams(search); try { - const { status, location } = await handleClick(params); + const { status, location } = await handleClick(params, countryCode); if (location && (status === 301 || status === 302)) { return res.redirect(location); } else { diff --git a/libs/pong/pong2.d.ts b/libs/pong/pong2.d.ts index 4b4dd1fafdab..242fdf7081fd 100644 --- a/libs/pong/pong2.d.ts +++ b/libs/pong/pong2.d.ts @@ -15,7 +15,8 @@ export function createPong2GetHandler( }>; export function createPong2ClickHandler(coder: Coder): ( - params: URLSearchParams + params: URLSearchParams, + countryCode: string ) => Promise<{ status: number; location: string; diff --git a/libs/pong/pong2.js b/libs/pong/pong2.js index 9ba544d3c9b8..376c3dfbc687 100644 --- a/libs/pong/pong2.js +++ b/libs/pong/pong2.js @@ -114,13 +114,20 @@ export function createPong2GetHandler(zoneKeys, coder) { } export function createPong2ClickHandler(coder) { - return async (params) => { + return async (params, countryCode) => { const click = coder.decodeAndVerify(params.get("code")); if (!click) { return {}; } - const res = await fetch(`https:${click}`, { redirect: "manual" }); + + const anonymousIp = anonymousIpByCC(countryCode); + const clickURL = new URL(click); + clickURL.searchParams.set("forwardedip", anonymousIp); + + const res = await fetch(`https:${clickURL.toString()}`, { + redirect: "manual", + }); const status = res.status; const location = res.headers.get("location"); return { status, location };