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.

fixed bug

Steven Tey26a85e548e5f
diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.ts
index 12a144ffbf..15877eca78 100644
--- a/apps/web/app/api/links/[linkId]/route.ts
+++ b/apps/web/app/api/links/[linkId]/route.ts
@@ -34,8 +34,22 @@ export const PUT = withAuth(
let { domain, key, url, rewrite } = updatedLink;
- // for default dub.sh links (not part of a project)
- if (!project) {
+ // if it's a custom project
+ if (project) {
+ if (project.domains?.find((d) => d.slug === domain)) {
+ return new Response("Domain does not belong to project.", {
+ status: 403,
+ headers,
+ });
+ }
+ // if it's not a custom project, do some filtering
+ } else {
+ if (domain !== "dub.sh") {
+ return new Response("Invalid domain", {
+ status: 403,
+ headers,
+ });
+ }
if (key.includes("/")) {
return new Response("Key cannot contain '/'.", {
status: 422,
@@ -63,13 +77,6 @@ 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 404
diff --git a/apps/web/app/api/links/route.ts b/apps/web/app/api/links/route.ts
index 01929afb07..421632fb08 100644
--- a/apps/web/app/api/links/route.ts
+++ b/apps/web/app/api/links/route.ts
@@ -69,8 +69,22 @@ export const POST = withAuth(
key = await getRandomKey(domain);
}
- // if it's not a custom project, do some filtering
- if (!project) {
+ // if it's a custom project
+ if (project) {
+ if (!project.domains?.find((d) => d.slug === domain)) {
+ return new Response("Domain does not belong to project.", {
+ status: 403,
+ headers,
+ });
+ }
+ // if it's not a custom project, do some filtering
+ } else {
+ if (domain !== "dub.sh") {
+ return new Response("Invalid domain", {
+ status: 403,
+ headers,
+ });
+ }
if (key.includes("/")) {
return new Response("Key cannot contain '/'.", {
status: 422,
@@ -108,13 +122,6 @@ 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,