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.

Limit unicode/diacritics normalization to Dub default domains

Steven Teycbdf06551107
diff --git a/apps/web/app/api/links/verify/route.ts b/apps/web/app/api/links/verify/route.ts
index e4309d1e4f..160102bee5 100644
--- a/apps/web/app/api/links/verify/route.ts
+++ b/apps/web/app/api/links/verify/route.ts
@@ -17,7 +17,7 @@ export const GET = async (req: NextRequest) => {
.and(workspaceIdSchema)
.parse(searchParams);
- const processedKey = processKey(key);
+ const processedKey = processKey({ domain, key });
if (processedKey === null) {
throw new DubApiError({
code: "unprocessable_entity",
diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.ts
index 807bd665e6..fe5a8e38a2 100644
--- a/apps/web/lib/api/links/process-link.ts
+++ b/apps/web/lib/api/links/process-link.ts
@@ -224,7 +224,7 @@ export async function processLink<T extends Record<string, any>>({
long: domain === "loooooooo.ng",
});
} else if (!skipKeyChecks) {
- const processedKey = processKey(key);
+ const processedKey = processKey({ domain, key });
if (processedKey === null) {
return {
link: payload,
diff --git a/apps/web/lib/api/links/utils.ts b/apps/web/lib/api/links/utils.ts
index 957d86c6a7..1b4b9bef5e 100644
--- a/apps/web/lib/api/links/utils.ts
+++ b/apps/web/lib/api/links/utils.ts
@@ -109,7 +109,7 @@ export async function keyChecks({
};
}
-export function processKey(key: string) {
+export function processKey({ domain, key }: { domain: string; key: string }) {
// Skip if root domain
if (key === "_root") {
return key;
@@ -125,8 +125,12 @@ export function processKey(key: string) {
// remove all leading and trailing slashes from key
key = key.replace(/^\/+|\/+$/g, "");
- // replace all special characters
- key = key.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
+ // for default dub domains, remove all special characters
+ // unicode normalization to remove accents / diacritical marks
+ // this is to prevent phishing/typo squatting
+ if (isDubDomain(domain)) {
+ key = key.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
+ }
// encode the key to ascii
key = punyEncode(key);