The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
restrict child link to parent link owner
Steven Teye4cdaefb96f2
diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.tsindex dca79512ac..c5a47da46d 100644--- a/apps/web/lib/api/links/process-link.ts+++ b/apps/web/lib/api/links/process-link.ts@@ -1,4 +1,8 @@-import { isBlacklistedDomain, updateConfig } from "@/lib/edge-config";+import {+ getFeatureFlags,+ isBlacklistedDomain,+ updateConfig,+} from "@/lib/edge-config";import { getPangeaDomainIntel } from "@/lib/pangea";import { checkIfUserExists, getRandomKey } from "@/lib/planetscale";import { prisma } from "@/lib/prisma";@@ -202,13 +206,33 @@ export async function processLink<T extends Record<string, any>>({};}- if (domain === "cal.link" && !workspace?.flags?.callink) {- return {- link: payload,- error:- "You can only use the cal.link domain if you have beta access to it. Contact [email protected] to get access.",- code: "forbidden",- };+ if (domain === "cal.link") {+ const flags = await getFeatureFlags({+ workspaceId: workspace?.id,+ });+ if (!flags?.callink) {+ return {+ link: payload,+ error:+ "You can only use the cal.link domain if you have beta access to it. Contact [email protected] to get access.",+ code: "forbidden",+ };+ }+ }++ if (key?.includes("/")) {+ // check if the user has access to the parent link+ const parentKey = key.split("/")[0];+ const parentLink = await prisma.link.findUnique({+ where: { domain_key: { domain, key: parentKey } },+ });+ if (parentLink?.userId !== userId) {+ return {+ link: payload,+ error: "You do not have access to this subdirectory.",+ code: "forbidden",+ };+ }}// else, check if the domain belongs to the workspacediff --git a/apps/web/lib/edge-config/get-feature-flags.ts b/apps/web/lib/edge-config/get-feature-flags.tsindex 93498fcd5e..21fc3f8d21 100644--- a/apps/web/lib/edge-config/get-feature-flags.ts+++ b/apps/web/lib/edge-config/get-feature-flags.ts@@ -23,6 +23,11 @@ export const getFeatureFlags = async ({};if (!process.env.NEXT_PUBLIC_IS_DUB || !process.env.EDGE_CONFIG) {+ // return all features as true if edge config is not available+ return Object.fromEntries(+ Object.entries(workspaceFeatures).map(([key, _v]) => [key, true]),+ );+ } else if (!workspaceId && !workspaceSlug) {return workspaceFeatures;}