Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Reject empty and non-integer earnings values in the share image route

Rafidbfad5c0b373
diff --git a/apps/web/app/api/og/partner-earnings/route.tsx b/apps/web/app/api/og/partner-earnings/route.tsx
index e2e02428c1..eced855f78 100644
--- a/apps/web/app/api/og/partner-earnings/route.tsx
+++ b/apps/web/app/api/og/partner-earnings/route.tsx
@@ -22,6 +22,8 @@ const querySchema = z.object({
// the earnings of each period in cents, comma separated
earnings: z
.string()
+ // whole numbers only, so an empty value (e.g. "0,") does not become 0
+ .regex(/^(-?\d+(,-?\d+)*)?$/, "Earnings must be comma-separated integers.")
.optional()
.default("")
.transform((value) => (value ? value.split(",").map(Number) : []))
diff --git a/apps/web/playwright/api/partner-profile/earnings.spec.ts b/apps/web/playwright/api/partner-profile/earnings.spec.ts
index b80d694c87..b82d17ff57 100644
--- a/apps/web/playwright/api/partner-profile/earnings.spec.ts
+++ b/apps/web/playwright/api/partner-profile/earnings.spec.ts
@@ -715,11 +715,14 @@ test.describe("GET /partner-profile/earnings", () => {
expect(response.status()).toEqual(200);
expect(response.headers()["content-type"]).toContain("image/png");
- const invalidResponse = await context.get(
- "/api/og/partner-earnings?earnings=0,abc",
- );
+ // an empty value ("0," or "1,,2") must not become 0
+ for (const earnings of ["0,abc", "0,", "1,,2", "1e3"]) {
+ const invalidResponse = await context.get(
+ `/api/og/partner-earnings?earnings=${earnings}`,
+ );
- expect(invalidResponse.status()).toEqual(422);
+ expect(invalidResponse.status()).toEqual(422);
+ }
} finally {
await context.dispose();
}