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.

fix handling slash

Steven Tey6aa770cfd3cd
diff --git a/app/protected/[domain]/[key]/action.ts b/app/protected/[domain]/[key]/action.ts
index a2173e7f0b..25892911cb 100644
--- a/app/protected/[domain]/[key]/action.ts
+++ b/app/protected/[domain]/[key]/action.ts
@@ -3,7 +3,8 @@ import prisma from "#/lib/prisma";
export async function verifyPassword(data: FormData) {
const domain = data.get("domain") as string;
- const key = data.get("key") as string;
+ const rawKey = data.get("key") as string; // keys can potentially be encoded
+ const key = decodeURIComponent(rawKey);
const password = data.get("password") as string;
const link = await prisma.link.findUnique({
diff --git a/app/proxy/[domain]/[key]/page.tsx b/app/proxy/[domain]/[key]/page.tsx
index 91ff687426..5c7c864815 100644
--- a/app/proxy/[domain]/[key]/page.tsx
+++ b/app/proxy/[domain]/[key]/page.tsx
@@ -11,7 +11,10 @@ export async function generateMetadata({
}: {
params: { domain: string; key: string };
}) {
- const data = await getLinkViaEdge(params.domain, params.key);
+ const domain = params.domain;
+ const key = decodeURIComponent(params.key); // key can potentially be encoded
+
+ const data = await getLinkViaEdge(domain, key);
if (!data || data.proxy === 0) {
return;
@@ -33,7 +36,10 @@ export default async function ProxyOGPage({
}: {
params: { domain: string; key: string };
}) {
- const data = await getLinkViaEdge(params.domain, params.key);
+ const domain = params.domain;
+ const key = decodeURIComponent(params.key);
+
+ const data = await getLinkViaEdge(domain, key);
// if the link doesn't exist
if (!data) {
diff --git a/lib/middleware/link.ts b/lib/middleware/link.ts
index f212be038d..192a8a22e6 100644
--- a/lib/middleware/link.ts
+++ b/lib/middleware/link.ts
@@ -62,9 +62,10 @@ export default async function LinkMiddleware(
} = response || {};
if (target) {
- if (inspectMode) {
+ // only show inspect model if the link is not password protected
+ if (inspectMode && !password) {
return NextResponse.rewrite(
- new URL(`/inspect/${domain}/${key}`, req.url),
+ new URL(`/inspect/${domain}/${encodeURIComponent(key)}`, req.url),
);
}
@@ -76,7 +77,7 @@ export default async function LinkMiddleware(
if (password) {
// rewrite to auth page (/protected/[domain]/[key]) if the link is password protected
return NextResponse.rewrite(
- new URL(`/protected/${domain}/${key}`, req.url),
+ new URL(`/protected/${domain}/${encodeURIComponent(key)}`, req.url),
);
}
@@ -86,7 +87,9 @@ export default async function LinkMiddleware(
const isBot = detectBot(req);
if (isBot && proxy) {
// rewrite to proxy page (/_proxy/[domain]/[key]) if it's a bot
- return NextResponse.rewrite(new URL(`/proxy/${domain}/${key}`, req.url));
+ return NextResponse.rewrite(
+ new URL(`/proxy/${domain}/${encodeURIComponent(key)}`, req.url),
+ );
} else if (ios && userAgent(req).os?.name === "iOS") {
// redirect to iOS link if it is specified and the user is on an iOS device
return NextResponse.redirect(getFinalUrl(ios, { req }), DUB_HEADERS);