Skip to content

Commit

Permalink
fix(cloud-function): sanitize pong/get input (#11229)
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner authored Jul 3, 2024
1 parent 4bd6950 commit a35254b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions libs/pong/pong2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@ import anonymousIpByCC from "./cc2ip.js";

export function createPong2GetHandler(zoneKeys, coder) {
return async (body, countryCode, userAgent) => {
const { pongs = null } = body;
let { pongs = null } = body;

// Validate.
if (!Array.isArray(pongs)) {
return { statusCode: 400, payload: { status: "invalid" } };
}

// Sanitize.
pongs = pongs.filter((p) => p in zoneKeys);

if (pongs.length == 0) {
return { statusCode: 400, payload: { status: "empty" } };
}

const anonymousIp = anonymousIpByCC(countryCode);

const placements = pongs
.filter((p) => p in zoneKeys)
.map((p) => {
return { name: p, zoneKey: [zoneKeys[p]] };
});
const placements = pongs.map((p) => {
return { name: p, zoneKey: [zoneKeys[p]] };
});

const requests = placements.map(async ({ name, zoneKey }) => {
const res = await (
Expand Down

0 comments on commit a35254b

Please sign in to comment.