The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fix fake click headers for non-Latin-1 region values (#4077)
Kiran Kab6e111d1527
diff --git a/apps/web/lib/tinybird/record-fake-click.ts b/apps/web/lib/tinybird/record-fake-click.tsindex 17d31bdb04..76464382dd 100644--- a/apps/web/lib/tinybird/record-fake-click.ts+++ b/apps/web/lib/tinybird/record-fake-click.ts@@ -3,6 +3,22 @@ import { Link } from "@prisma/client";import { clickEventSchemaTB } from "../zod/schemas/clicks";import { recordClick } from "./record-click";+// HTTP headers must be ByteString (Latin-1); non-Latin-1 values cause fetch to throw.+function toSafeHeaderValue(value: string | null | undefined) {+ if (!value) {+ return null;+ }++ // We return "Unknown" for non-Latin-1 values.+ for (let i = 0; i < value.length; i++) {+ if (value.charCodeAt(i) > 255) {+ return "Unknown";+ }+ }++ return value;+}+// TODO:// Use this in other places where we need to record a fake click event (Eg: import-customers)export async function recordFakeClick({@@ -22,9 +38,9 @@ export async function recordFakeClick({headers: new Headers({"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)","x-forwarded-for": "127.0.0.1",- "x-vercel-ip-country": customer?.country || "US",- "x-vercel-ip-country-region": customer?.region || "CA",- "x-vercel-ip-continent": customer?.continent || "NA",+ "x-vercel-ip-country": toSafeHeaderValue(customer?.country) || "US",+ "x-vercel-ip-country-region": toSafeHeaderValue(customer?.region) || "CA",+ "x-vercel-ip-continent": toSafeHeaderValue(customer?.continent) || "NA",}),});