Skip to content

Commit

Permalink
Merge branch 'main' into utm-templates
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Oct 15, 2024
2 parents 6c46fb2 + fae5460 commit 889f5da
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion apps/web/app/app.dub.co/(auth)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function AuthLayout({ children }: { children: ReactNode }) {
<Providers>
<Toolbar />
<Background />
<div className="relative z-10 flex min-h-screen w-screen justify-center">
<div className="relative z-10 flex min-h-screen w-full justify-center">
{children}
</div>
</Providers>
Expand Down
9 changes: 6 additions & 3 deletions apps/web/lib/api/links/utils/key-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import {
} from "@/lib/edge-config";
import { checkIfKeyExists } from "@/lib/planetscale";
import { WorkspaceProps } from "@/lib/types";
import { DEFAULT_REDIRECTS, isDubDomain } from "@dub/utils";
import { RESERVED_PATHS } from "@dub/utils/src/constants/middleware";
import {
DEFAULT_REDIRECTS,
isDubDomain,
isReservedKeyGlobal,
} from "@dub/utils";

export async function keyChecks({
domain,
Expand All @@ -26,7 +29,7 @@ export async function keyChecks({
};
}

if (RESERVED_PATHS.includes(key)) {
if (isReservedKeyGlobal(key)) {
return {
error: `${key} is a reserved path and cannot be used as a short link.`,
code: "forbidden",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/lib/api/links/utils/process-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function processKey({ domain, key }: { domain: string; key: string }) {
return null;
}

// if key ends with .php, return null (we don't support .php in links)
// check if key is supported
if (isUnsupportedKey(key)) {
return null;
}
Expand Down
8 changes: 0 additions & 8 deletions packages/utils/src/constants/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ export const DEFAULT_REDIRECTS = {
discord: "https://twitter.com/dubdotco", // placeholder for now
};

export const RESERVED_PATHS = [
"favicon.ico",
"sitemap.xml",
"robots.txt",
"manifest.webmanifest",
".well-known",
];

export const DUB_HEADERS = {
"x-powered-by": "Dub.co - Link management for modern marketing teams",
};
20 changes: 18 additions & 2 deletions packages/utils/src/functions/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ export const validKeyRegex = new RegExp(
);

export const isUnsupportedKey = (key: string) => {
const unsupportedExtensions = [".php", ".php7"];
return unsupportedExtensions.some((extension) => key.endsWith(extension));
const excludedPrefix = [".well-known"];
const excludedSuffix = [".php", ".php7"];
return (
excludedPrefix.some((prefix) => key.startsWith(prefix)) ||
excludedSuffix.some((suffix) => key.endsWith(suffix))
);
};

export const isReservedKeyGlobal = (key: string) => {
const reservedKeys = [
"favicon.ico",
"sitemap.xml",
"robots.txt",
"manifest.webmanifest",
"manifest.json",
"apple-app-site-association",
];
return reservedKeys.includes(key);
};

0 comments on commit 889f5da

Please sign in to comment.