The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Merge branch 'main' of https://github.com/steven-tey/dub
Steven Tey0a189d03c389
diff --cc lib/auth.tsindex 8c833e28d6,6c8c1aa511..c5d6d1745a--- a/lib/auth.ts+++ b/lib/auth.ts@@@ -310,18 -282,56 +287,43 @@@ const withLinksAuthreturn res.status(403).end("Unauthorized: Need higher plan.");}- // if domain is defined- if (domain) {- // prevent domain from being query injected by- // comparing the domain in the query params to the domain in the body- if (req.body.domain && req.body.domain !== domain) {- return res.status(403).end("Unauthorized: Invalid domain.");- }-- // check if the domain is part of the project- const domainProjectId = await prisma.domain.findUnique({- where: {- slug: domain,- },- select: {- projectId: true,- },- });- if (domainProjectId?.projectId !== project.id) {- return res.status(403).end("Unauthorized: Invalid domain.");- }+ // prevent unauthorized access to domains+ if (+ (domain && !project.domains?.find((d) => d.slug === domain)) ||+ (req.body.domain &&+ !project.domains?.find((d) => d.slug === req.body.domain))+ ) {+ return res.status(403).end("Unauthorized: Invalid domain.");}}+ }- return handler(req, res, session, project, domain);+ // if key is defined, check if the current user is the owner of the link+ const { key } = req.query;+ if (key) {+ if (typeof key !== "string") {+ return res.status(400).end("Missing or misconfigured link key.");+ } else {+ link =+ (await prisma.link.findUnique({+ where: {+ domain_key: {+ domain: domain || "dub.sh",+ key,+ },+ },+ })) || undefined;+ if (!link) {+ return res.status(404).end("Link not found.");++ // for dub.sh links, check if the user is the owner of the link+ } else if (!slug && link.userId !== session.user.id) {+ return res.status(403).end("Unauthorized: Not link owner.");+ }+ }}++ return handler(req, res, session, project, domain, link);};export { withLinksAuth };