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.

Allow programs to disable customerEmailMatch and customerEmailSuspiciousDomain fraud rules

Kiran K47e0bdc49809
diff --git a/apps/web/app/(ee)/api/fraud/rules/route.ts b/apps/web/app/(ee)/api/fraud/rules/route.ts
index 6d93158018..179d87f232 100644
--- a/apps/web/app/(ee)/api/fraud/rules/route.ts
+++ b/apps/web/app/(ee)/api/fraud/rules/route.ts
@@ -55,23 +55,38 @@ export const PATCH = withWorkspace(
async ({ workspace, req, session }) => {
const programId = getDefaultProgramIdOrThrow(workspace);
- const { referralSourceBanned, paidTrafficDetected } =
- updateFraudRuleSettingsSchema.parse(await parseRequestBody(req));
+ const {
+ referralSourceBanned,
+ paidTrafficDetected,
+ customerEmailMatch,
+ customerEmailSuspiciousDomain,
+ } = updateFraudRuleSettingsSchema.parse(await parseRequestBody(req));
const rulesToUpdate = [
{
- type: "referralSourceBanned" as FraudRuleType,
+ type: FraudRuleType.referralSourceBanned,
payload: referralSourceBanned,
},
{
- type: "paidTrafficDetected" as FraudRuleType,
+ type: FraudRuleType.paidTrafficDetected,
payload: paidTrafficDetected,
},
+ {
+ type: FraudRuleType.customerEmailMatch,
+ payload: customerEmailMatch,
+ },
+ {
+ type: FraudRuleType.customerEmailSuspiciousDomain,
+ payload: customerEmailSuspiciousDomain,
+ },
].filter((r) => r.payload);
for (const { type, payload } of rulesToUpdate) {
if (!payload) continue;
+ const config =
+ "config" in payload ? payload.config ?? Prisma.DbNull : Prisma.DbNull;
+
await prisma.fraudRule.upsert({
where: {
programId_type: {
@@ -83,11 +98,11 @@ export const PATCH = withWorkspace(
id: createId({ prefix: "fr_" }),
programId,
type,
- config: payload.config ?? Prisma.DbNull,
+ config,
disabledAt: payload.enabled ? null : new Date(),
},
update: {
- config: payload.config ?? Prisma.DbNull,
+ config,
disabledAt: payload.enabled ? null : new Date(),
},
});
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/fraud/fraud-customer-email-match-settings.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/fraud/fraud-customer-email-match-settings.tsx
new file mode 100644
index 0000000000..0547bb83b6
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/fraud/fraud-customer-email-match-settings.tsx
@@ -0,0 +1,47 @@
+"use client";
+
+import { UpdateFraudRuleSettings } from "@/lib/types";
+import { Switch } from "@dub/ui";
+import { useFormContext } from "react-hook-form";
+
+interface FraudCustomerEmailMatchSettingsProps {
+ isConfigLoading?: boolean;
+}
+
+export function FraudCustomerEmailMatchSettings({
+ isConfigLoading = false,
+}: FraudCustomerEmailMatchSettingsProps) {
+ const {
+ watch,
+ setValue,
+ formState: { isSubmitting },
+ } = useFormContext<UpdateFraudRuleSettings>();
+
+ const enabled = watch("customerEmailMatch.enabled");
+ const isDisabled = isConfigLoading || isSubmitting;
+
+ return (
+ <div className="rounded-xl border border-neutral-200">
+ <div className="flex items-center justify-between p-3">
+ <div className="flex-1">
+ <h3 className="text-sm font-semibold text-neutral-900">
+ Matching customer email
+ </h3>
+ <p className="text-content-subtle mt-0.5 text-xs font-normal tracking-normal">
+ Flag when a partner&apos;s email matches a customer&apos;s email
+ </p>
+ </div>
+ <Switch
+ trackDimensions="radix-state-checked:bg-black focus-visible:ring-black/20"
+ checked={enabled}
+ disabled={isDisabled}
+ fn={(enabled: boolean) => {
+ setValue("customerEmailMatch.enabled", enabled, {
+ shouldDirty: true,
+ });
+ }}
+ />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/fraud/fraud-customer-email-suspicious-domain-settings.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/fraud/fraud-customer-email-suspicious-domain-settings.tsx
new file mode 100644
index 0000000000..e190277df9
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/fraud/fraud-customer-email-suspicious-domain-settings.tsx
@@ -0,0 +1,47 @@
+"use client";
+
+import { UpdateFraudRuleSettings } from "@/lib/types";
+import { Switch } from "@dub/ui";
+import { useFormContext } from "react-hook-form";
+
+interface FraudCustomerEmailSuspiciousDomainSettingsProps {
+ isConfigLoading?: boolean;
+}
+
+export function FraudCustomerEmailSuspiciousDomainSettings({
+ isConfigLoading = false,
+}: FraudCustomerEmailSuspiciousDomainSettingsProps) {
+ const {
+ watch,
+ setValue,
+ formState: { isSubmitting },
+ } = useFormContext<UpdateFraudRuleSettings>();
+
+ const enabled = watch("customerEmailSuspiciousDomain.enabled");
+ const isDisabled = isConfigLoading || isSubmitting;
+
+ return (
+ <div className="rounded-xl border border-neutral-200">
+ <div className="flex items-center justify-between p-3">
+ <div className="flex-1">
+ <h3 className="text-sm font-semibold text-neutral-900">
+ Suspicious customer email domain
+ </h3>
+ <p className="text-content-subtle mt-0.5 text-xs font-normal tracking-normal">
+ Flag customers using disposable or temporary email domains
+ </p>
+ </div>
+ <Switch
+ trackDimensions="radix-state-checked:bg-black focus-visible:ring-black/20"
+ checked={enabled}
+ disabled={isDisabled}
+ fn={(enabled: boolean) => {
+ setValue("customerEmailSuspiciousDomain.enabled", enabled, {
+ shouldDirty: true,
+ });
+ }}
+ />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/fraud/program-fraud-settings-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/fraud/program-fraud-settings-sheet.tsx
index 2bd97ce0d2..2ff679f438 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/fraud/program-fraud-settings-sheet.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/fraud/program-fraud-settings-sheet.tsx
@@ -19,6 +19,8 @@ import { Dispatch, SetStateAction, useEffect, useState } from "react";
import { FormProvider, useForm } from "react-hook-form";
import { toast } from "sonner";
import useSWR from "swr";
+import { FraudCustomerEmailMatchSettings } from "./fraud-customer-email-match-settings";
+import { FraudCustomerEmailSuspiciousDomainSettings } from "./fraud-customer-email-suspicious-domain-settings";
import { FraudPaidTrafficSettings } from "./fraud-paid-traffic-settings";
import { FraudReferralSourceSettings } from "./fraud-referral-source-settings";
@@ -50,6 +52,12 @@ function ProgramFraudSettingsSheetContent({
enabled: false,
config: { platforms: [], google: { whitelistedCampaignIds: [] } },
},
+ customerEmailMatch: {
+ enabled: true,
+ },
+ customerEmailSuspiciousDomain: {
+ enabled: true,
+ },
},
});
@@ -69,6 +77,14 @@ function ProgramFraudSettingsSheetContent({
(rule) => rule.type === "paidTrafficDetected",
);
+ const customerEmailMatchRule = fraudRules.find(
+ (rule) => rule.type === "customerEmailMatch",
+ );
+
+ const customerEmailSuspiciousDomainRule = fraudRules.find(
+ (rule) => rule.type === "customerEmailSuspiciousDomain",
+ );
+
const paidTrafficConfig = (paidTrafficDetectedRule?.config ?? {}) as {
platforms?: PaidTrafficPlatform[];
google?: { whitelistedCampaignIds?: string[] };
@@ -89,6 +105,12 @@ function ProgramFraudSettingsSheetContent({
},
},
},
+ customerEmailMatch: {
+ enabled: customerEmailMatchRule?.enabled ?? true,
+ },
+ customerEmailSuspiciousDomain: {
+ enabled: customerEmailSuspiciousDomainRule?.enabled ?? true,
+ },
});
}, [fraudRules, form]);
@@ -165,6 +187,10 @@ function ProgramFraudSettingsSheetContent({
<div className="space-y-4">
<FraudPaidTrafficSettings isConfigLoading={isLoading} />
<FraudReferralSourceSettings isConfigLoading={isLoading} />
+ <FraudCustomerEmailMatchSettings isConfigLoading={isLoading} />
+ <FraudCustomerEmailSuspiciousDomainSettings
+ isConfigLoading={isLoading}
+ />
</div>
</div>
diff --git a/apps/web/lib/api/fraud/constants.ts b/apps/web/lib/api/fraud/constants.ts
index dafe910953..26c9fc03bf 100644
--- a/apps/web/lib/api/fraud/constants.ts
+++ b/apps/web/lib/api/fraud/constants.ts
@@ -8,7 +8,7 @@ export const FRAUD_RULES: FraudRuleInfo[] = [
description:
"Partner's email matches a customer's email and could be a self referral.",
scope: "conversionEvent",
- configurable: false,
+ configurable: true,
},
{
type: "customerEmailSuspiciousDomain",
@@ -16,7 +16,7 @@ export const FRAUD_RULES: FraudRuleInfo[] = [
description:
"Customer's email uses a disposable or temporary domain which could be a fraud attempt.",
scope: "conversionEvent",
- configurable: false,
+ configurable: true,
},
{
type: "referralSourceBanned",
diff --git a/apps/web/lib/zod/schemas/fraud.ts b/apps/web/lib/zod/schemas/fraud.ts
index 9666fb57f2..e0400fb1a7 100644
--- a/apps/web/lib/zod/schemas/fraud.ts
+++ b/apps/web/lib/zod/schemas/fraud.ts
@@ -228,6 +228,22 @@ export const updateFraudRuleSettingsSchema = z.object({
return data;
})
.optional(),
+
+ // Customer email match rule (toggle-only)
+ customerEmailMatch: z
+ .object({
+ resolvePendingEvents: z.boolean().default(false),
+ enabled: z.boolean(),
+ })
+ .optional(),
+
+ // Customer email suspicious domain rule (toggle-only)
+ customerEmailSuspiciousDomain: z
+ .object({
+ resolvePendingEvents: z.boolean().default(false),
+ enabled: z.boolean(),
+ })
+ .optional(),
});
export const fraudEventSchemas = {
diff --git a/apps/web/ui/modals/disable-fraud-rules-modal.tsx b/apps/web/ui/modals/disable-fraud-rules-modal.tsx
index ce30bf29d7..c54dce8b28 100644
--- a/apps/web/ui/modals/disable-fraud-rules-modal.tsx
+++ b/apps/web/ui/modals/disable-fraud-rules-modal.tsx
@@ -14,6 +14,8 @@ import useSWR from "swr";
export const CONFIGURABLE_RULE_TYPES = [
"referralSourceBanned",
"paidTrafficDetected",
+ "customerEmailMatch",
+ "customerEmailSuspiciousDomain",
] as const;
export type ConfigurableRuleType = (typeof CONFIGURABLE_RULE_TYPES)[number];
@@ -30,6 +32,14 @@ const RULE_DETAILS: Record<
title: "Paid traffic",
description: "Flag paid advertising traffic",
},
+ customerEmailMatch: {
+ title: "Matching customer email",
+ description: "Flag when a partner's email matches a customer's email",
+ },
+ customerEmailSuspiciousDomain: {
+ title: "Suspicious customer email domain",
+ description: "Flag customers using disposable or temporary email domains",
+ },
};
interface DisableFraudRulesModalProps {
@@ -200,12 +210,22 @@ export function getRulesBeingDisabled({
paidTrafficDetected:
previousFraudRules?.find((r) => r.type === "paidTrafficDetected")
?.enabled ?? false,
+ customerEmailMatch:
+ previousFraudRules?.find((r) => r.type === "customerEmailMatch")
+ ?.enabled ?? false,
+ customerEmailSuspiciousDomain:
+ previousFraudRules?.find(
+ (r) => r.type === "customerEmailSuspiciousDomain",
+ )?.enabled ?? false,
};
// Build "next" map from form
const next: Record<ConfigurableRuleType, boolean> = {
referralSourceBanned: nextFraudRules.referralSourceBanned?.enabled ?? false,
paidTrafficDetected: nextFraudRules.paidTrafficDetected?.enabled ?? false,
+ customerEmailMatch: nextFraudRules.customerEmailMatch?.enabled ?? false,
+ customerEmailSuspiciousDomain:
+ nextFraudRules.customerEmailSuspiciousDomain?.enabled ?? false,
};
// Detect rule disable transitions