The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fixed domain auth bug
Steven Tey526dc68fb21a
diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.tsindex cb0e662a2b..12a144ffbf 100644--- a/apps/web/app/api/links/[linkId]/route.ts+++ b/apps/web/app/api/links/[linkId]/route.ts@@ -11,7 +11,7 @@ export const PUT = withAuth(try {body = await req.json();} catch (error) {- return new Response("Missing body.", { status: 400, headers });+ return new Response("Missing or invalid body.", { status: 400, headers });}if (Object.keys(body).length === 0) {return new Response("No fields to update.", { status: 304, headers });@@ -32,7 +32,7 @@ export const PUT = withAuth();}- let { key, url, rewrite } = updatedLink;+ let { domain, key, url, rewrite } = updatedLink;// for default dub.sh links (not part of a project)if (!project) {@@ -63,6 +63,13 @@ export const PUT = withAuth(return new Response("Invalid key.", { status: 422, headers });}+ if (!project.domains?.find((d) => d.slug === domain)) {+ return new Response("Domain does not belong to project.", {+ status: 403,+ headers,+ });+ }+const [response, invalidFavicon] = await Promise.allSettled([editLink({// link is guaranteed to exist because if not we will return 404diff --git a/apps/web/app/api/links/route.ts b/apps/web/app/api/links/route.tsindex 6272c67aa4..01929afb07 100644--- a/apps/web/app/api/links/route.ts+++ b/apps/web/app/api/links/route.ts@@ -46,7 +46,13 @@ export const GET = withAuth(// POST /api/links – create a new linkexport const POST = withAuth(async ({ req, headers, session, project }) => {- const body = await req.json();+ let body;+ try {+ body = await req.json();+ } catch (error) {+ return new Response("Missing or invalid body.", { status: 400, headers });+ }+let { domain, key, url, rewrite, geo } = body;if (!url) {@@ -102,6 +108,13 @@ export const POST = withAuth(return new Response("Invalid key.", { status: 422, headers });}+ if (!project.domains?.find((d) => d.slug === domain)) {+ return new Response("Domain does not belong to project.", {+ status: 403,+ headers,+ });+ }+const [response, invalidFavicon] = await Promise.allSettled([addLink({...body,diff --git a/apps/web/lib/auth/index.ts b/apps/web/lib/auth/index.tsindex a05ee96bed..3bffc1ab8d 100644--- a/apps/web/lib/auth/index.ts+++ b/apps/web/lib/auth/index.ts@@ -218,8 +218,8 @@ export const withAuth =// prevent unauthorized access to domains that don't belong to the projectif (domain) {if (!project.domains?.find((d) => d.slug === domain)) {- return new Response("Domain not found.", {- status: 404,+ return new Response("Domain does not belong to project.", {+ status: 403,headers,});}@@ -227,7 +227,7 @@ export const withAuth =if (link && link.projectId !== project.id) {return new Response("Unauthorized: Invalid link.", {- status: 401,+ status: 403,headers,});}@@ -315,7 +315,7 @@ export const withAuth =// if it's the default dub.sh link, we need to make sure the user is the owner of the linkif (link.domain === "dub.sh" && link.userId !== session.user.id) {return new Response("Unauthorized: Invalid link.", {- status: 401,+ status: 403,headers,});}