The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update URL schemas to enforce a maximum length of 32,000 characters
Kiran Ke0636b00aa02
diff --git a/apps/web/lib/zod/schemas/groups.ts b/apps/web/lib/zod/schemas/groups.tsindex 92a4a17228..5e9feee511 100644--- a/apps/web/lib/zod/schemas/groups.ts+++ b/apps/web/lib/zod/schemas/groups.ts@@ -60,7 +60,7 @@ export const GroupSchemaExtended = GroupSchema.extend({});export const createOrUpdateDefaultLinkSchema = z.object({- url: parseUrlSchema,+ url: parseUrlSchema({ maxLength: 32000 }),});export const createGroupSchema = z.object({@@ -100,7 +100,7 @@ export const updateGroupSchema = createGroupSchema.partial().extend({export const PartnerGroupDefaultLinkSchema = z.object({id: z.string(),domain: z.string(),- url: parseUrlSchema,+ url: parseUrlSchema({ maxLength: 32000 }),});export const getGroupsQuerySchema = zdiff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.tsindex a0e613d4a4..fdd2a15ecc 100644--- a/apps/web/lib/zod/schemas/links.ts+++ b/apps/web/lib/zod/schemas/links.ts@@ -15,7 +15,7 @@ import {} from "./utils";export const getUrlQuerySchema = z.object({- url: parseUrlSchema,+ url: parseUrlSchema(),});export const getDomainQuerySchema = z.object({@@ -222,7 +222,7 @@ export const domainKeySchema = z.object({});export const createLinkBodySchema = z.object({- url: parseUrlSchemaAllowEmpty()+ url: parseUrlSchemaAllowEmpty({ maxLength: 32000 }).describe("The destination URL of the short link.").openapi({example: "https://google.com",@@ -316,7 +316,7 @@ export const createLinkBodySchema = z.object({.string().nullish().describe("The date and time when the short link will expire at."),- expiredUrl: parseUrlSchema+ expiredUrl: parseUrlSchema({ maxLength: 32000 }).nullish().describe("The URL to redirect to when the short link has expired."),password: z@@ -361,18 +361,18 @@ export const createLinkBodySchema = z.object({.describe("Whether the short link uses link cloaking. Defaults to `false` if not provided.",),- ios: parseUrlSchema+ ios: parseUrlSchema({ maxLength: 32000 }).nullish().describe("The iOS destination URL for the short link for iOS device targeting.",),- android: parseUrlSchema+ android: parseUrlSchema({ maxLength: 32000 }).nullish().describe("The Android destination URL for the short link for Android device targeting.",),geo: z- .record(z.string(), parseUrlSchema)+ .record(z.string(), parseUrlSchema({ maxLength: 32000 })).nullish().describe("Geo targeting information for the short link in JSON format `{[COUNTRY]: https://example.com }`. See https://d.to/geo for more information.",@@ -497,7 +497,7 @@ export const bulkUpdateLinksBodySchema = z.object({}).merge(z.object({- url: parseUrlSchema+ url: parseUrlSchema({ maxLength: 32000 }).describe("The destination URL of the short link.").openapi({example: "https://google.com",diff --git a/apps/web/lib/zod/schemas/opens.ts b/apps/web/lib/zod/schemas/opens.tsindex 366548aa71..e967885cfb 100644--- a/apps/web/lib/zod/schemas/opens.ts+++ b/apps/web/lib/zod/schemas/opens.ts@@ -3,7 +3,7 @@ import { z } from "zod";export const trackOpenRequestSchema = z.object({- deepLink: parseUrlSchema+ deepLink: parseUrlSchema().optional().describe("The deep link that brought the user to the app. If left blank, Dub will fallback to probabilistic tracking by using the `dubDomain` parameter to check if there is an associated click event for the user's IP address. Learn more: https://d.to/ddl",diff --git a/apps/web/lib/zod/schemas/partners.ts b/apps/web/lib/zod/schemas/partners.tsindex e3fddc7791..a0ca33bacd 100644--- a/apps/web/lib/zod/schemas/partners.ts+++ b/apps/web/lib/zod/schemas/partners.ts@@ -529,7 +529,7 @@ export const createPartnerLinkSchema = z.describe("The ID of the partner in your system. If both `partnerId` and `tenantId` are not provided, an error will be thrown.",),- url: parseUrlSchema+ url: parseUrlSchema({ maxLength: 32000 }).describe("The URL to shorten (if not provided, the program's default URL will be used). Will throw an error if the domain doesn't match the program's default URL domain.",)@@ -551,7 +551,7 @@ export const createPartnerLinkSchema = zexport const upsertPartnerLinkSchema = createPartnerLinkSchema.merge(z.object({- url: parseUrlSchema.describe(+ url: parseUrlSchema({ maxLength: 32000 }).describe("The URL to upsert for. Will throw an error if the domain doesn't match the program's default URL domain.",),}),diff --git a/apps/web/lib/zod/schemas/program-onboarding.ts b/apps/web/lib/zod/schemas/program-onboarding.tsindex 5a84cbc22c..8771d9fc98 100644--- a/apps/web/lib/zod/schemas/program-onboarding.ts+++ b/apps/web/lib/zod/schemas/program-onboarding.ts@@ -10,7 +10,7 @@ export const programInfoSchema = z.object({name: z.string().max(100),logo: z.string(),domain: z.string(),- url: parseUrlSchema.nullable(),+ url: parseUrlSchema({ maxLength: 32000 }).nullable(),linkStructure: z.nativeEnum(PartnerLinkStructure).default("short"),linkParameter: z.string().nullish(),});diff --git a/apps/web/lib/zod/schemas/qr.ts b/apps/web/lib/zod/schemas/qr.tsindex 02f61c36c0..e20212e109 100644--- a/apps/web/lib/zod/schemas/qr.ts+++ b/apps/web/lib/zod/schemas/qr.ts@@ -9,7 +9,7 @@ import { booleanQuerySchema } from "./misc";import { parseUrlSchema } from "./utils";export const getQRCodeQuerySchema = z.object({- url: parseUrlSchema.describe("The URL to generate a QR code for."),+ url: parseUrlSchema().describe("The URL to generate a QR code for."),logo: z.string().optional()diff --git a/apps/web/lib/zod/schemas/utils.ts b/apps/web/lib/zod/schemas/utils.tsindex f8d783dec5..644631df96 100644--- a/apps/web/lib/zod/schemas/utils.ts+++ b/apps/web/lib/zod/schemas/utils.ts@@ -1,10 +1,19 @@import z from "@/lib/zod";import { getUrlFromString, isValidUrl, parseDateTime } from "@dub/utils";-export const parseUrlSchema = z- .string()- .transform((v) => getUrlFromString(v))- .refine((v) => isValidUrl(v), { message: "Invalid URL" });+export const parseUrlSchema = ({ maxLength }: { maxLength?: number } = {}) => {+ let schema = z.string();++ if (maxLength) {+ schema = schema.max(maxLength, {+ message: `Must be ${maxLength} or fewer characters long.`,+ });+ }++ return schema+ .transform((v) => getUrlFromString(v))+ .refine((v) => isValidUrl(v), { message: "Invalid URL" });+};export const parseUrlSchemaAllowEmpty = ({maxLength,diff --git a/apps/web/lib/zod/schemas/webhooks.ts b/apps/web/lib/zod/schemas/webhooks.tsindex 96e08bb945..d129eb0546 100644--- a/apps/web/lib/zod/schemas/webhooks.ts+++ b/apps/web/lib/zod/schemas/webhooks.ts@@ -15,7 +15,7 @@ export const WebhookSchema = z.object({export const createWebhookSchema = z.object({name: z.string().min(1).max(40),- url: parseUrlSchema,+ url: parseUrlSchema(),secret: z.string().optional(),triggers: z.array(z.enum(WEBHOOK_TRIGGERS)),linkIds: z.array(z.string()).optional(),diff --git a/apps/web/ui/messages/messages-panel.tsx b/apps/web/ui/messages/messages-panel.tsxindex 190c2977d2..37e73c701b 100644--- a/apps/web/ui/messages/messages-panel.tsx+++ b/apps/web/ui/messages/messages-panel.tsx@@ -286,9 +286,9 @@ function StatusIndicator({<divclassName={cn("text-content-subtle flex items-center",- message.readInApp+ message.readInApp? "text-blue-500"- : (message.readInEmail && "text-violet-500"),+ : message.readInEmail && "text-violet-500",)}>{message.delivered === false ? (diff --git a/packages/ui/src/icons/payout-platforms/stripe.tsx b/packages/ui/src/icons/payout-platforms/stripe.tsxindex 4797dff761..c5d778a8f9 100644--- a/packages/ui/src/icons/payout-platforms/stripe.tsx+++ b/packages/ui/src/icons/payout-platforms/stripe.tsx@@ -17,4 +17,3 @@ export function Stripe({ className }: { className?: string }) {</svg>);}-