Skip to content

Commit fae5460

Browse files
committed
isReservedKeyGlobal, isUnsupportedKey
1 parent 679cb09 commit fae5460

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

apps/web/lib/api/links/utils/key-checks.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import {
66
} from "@/lib/edge-config";
77
import { checkIfKeyExists } from "@/lib/planetscale";
88
import { WorkspaceProps } from "@/lib/types";
9-
import { DEFAULT_REDIRECTS, isDubDomain } from "@dub/utils";
10-
import { RESERVED_PATHS } from "@dub/utils/src/constants/middleware";
9+
import {
10+
DEFAULT_REDIRECTS,
11+
isDubDomain,
12+
isReservedKeyGlobal,
13+
} from "@dub/utils";
1114

1215
export async function keyChecks({
1316
domain,
@@ -26,7 +29,7 @@ export async function keyChecks({
2629
};
2730
}
2831

29-
if (RESERVED_PATHS.includes(key)) {
32+
if (isReservedKeyGlobal(key)) {
3033
return {
3134
error: `${key} is a reserved path and cannot be used as a short link.`,
3235
code: "forbidden",

apps/web/lib/api/links/utils/process-key.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function processKey({ domain, key }: { domain: string; key: string }) {
1919
return null;
2020
}
2121

22-
// if key ends with .php, return null (we don't support .php in links)
22+
// check if key is supported
2323
if (isUnsupportedKey(key)) {
2424
return null;
2525
}

packages/utils/src/constants/middleware.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ export const DEFAULT_REDIRECTS = {
1313
discord: "https://twitter.com/dubdotco", // placeholder for now
1414
};
1515

16-
export const RESERVED_PATHS = [
17-
"favicon.ico",
18-
"sitemap.xml",
19-
"robots.txt",
20-
"manifest.webmanifest",
21-
".well-known",
22-
];
23-
2416
export const DUB_HEADERS = {
2517
"x-powered-by": "Dub.co - Link management for modern marketing teams",
2618
};

packages/utils/src/functions/keys.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ export const validKeyRegex = new RegExp(
44
);
55

66
export const isUnsupportedKey = (key: string) => {
7-
const unsupportedExtensions = [".php", ".php7"];
8-
return unsupportedExtensions.some((extension) => key.endsWith(extension));
7+
const excludedPrefix = [".well-known"];
8+
const excludedSuffix = [".php", ".php7"];
9+
return (
10+
excludedPrefix.some((prefix) => key.startsWith(prefix)) ||
11+
excludedSuffix.some((suffix) => key.endsWith(suffix))
12+
);
13+
};
14+
15+
export const isReservedKeyGlobal = (key: string) => {
16+
const reservedKeys = [
17+
"favicon.ico",
18+
"sitemap.xml",
19+
"robots.txt",
20+
"manifest.webmanifest",
21+
"manifest.json",
22+
"apple-app-site-association",
23+
];
24+
return reservedKeys.includes(key);
925
};

0 commit comments

Comments
 (0)