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.

Check number field limits on the server when a lead is submitted

Rafid70089c95a18
diff --git a/apps/web/lib/submitted-leads/submit-lead-action.ts b/apps/web/lib/submitted-leads/submit-lead-action.ts
index 2c13e2873c..f22742360a 100644
--- a/apps/web/lib/submitted-leads/submit-lead-action.ts
+++ b/apps/web/lib/submitted-leads/submit-lead-action.ts
@@ -147,6 +147,27 @@ export const submitLeadAction = authPartnerActionClient
if (!fieldSchema) continue;
+ if (fieldSchema.type === "number") {
+ const { min, max } = fieldSchema.constraints ?? {};
+
+ if (
+ (min !== undefined && !(typeof value === "number" && value >= min)) ||
+ (max !== undefined && !(typeof value === "number" && value <= max))
+ ) {
+ const range =
+ min !== undefined && max !== undefined
+ ? `between ${min} and ${max}`
+ : min !== undefined
+ ? `at least ${min}`
+ : `at most ${max}`;
+
+ throw new DubApiError({
+ code: "bad_request",
+ message: `${fieldSchema.label} must be ${range}.`,
+ });
+ }
+ }
+
customFormData.push({
key,
label: fieldSchema.label || key,