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.

Cloaked query plus encoding (#4087)

Pedro Ladeirabb99f0a1d1a5
diff --git a/apps/web/app/cloaked/[url]/page.tsx b/apps/web/app/cloaked/[url]/page.tsx
index 59446e5c16..ee373d7c36 100644
--- a/apps/web/app/cloaked/[url]/page.tsx
+++ b/apps/web/app/cloaked/[url]/page.tsx
@@ -5,11 +5,25 @@ import {
} from "@dub/utils";
import { getMetaTags } from "app/api/links/metatags/utils";
+function getCloakedDestinationUrl(param: string): string {
+ // Next.js decodes dynamic route segments once. Only decode again when the
+ // param is still fully encoded.
+ if (/^https?%3A/i.test(param)) {
+ try {
+ return decodeURIComponent(param);
+ } catch {
+ return param;
+ }
+ }
+
+ return param;
+}
+
export async function generateMetadata(props: {
params: Promise<{ url: string }>;
}) {
const params = await props.params;
- const url = decodeURIComponent(params.url); // key can potentially be encoded
+ const url = getCloakedDestinationUrl(params.url);
const metatags = await getMetaTags(url);
const apexDomain = getApexDomain(url);
@@ -27,7 +41,7 @@ export default async function CloakedPage(props: {
params: Promise<{ url: string }>;
}) {
const params = await props.params;
- const url = decodeURIComponent(params.url);
+ const url = getCloakedDestinationUrl(params.url);
return <iframe src={url} className="min-h-screen w-full border-none" />;
}