The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Enforce workspace membership before installing integrations.
Kiran K5c7d57d772bb
diff --git a/apps/web/app/(ee)/api/hubspot/callback/route.ts b/apps/web/app/(ee)/api/hubspot/callback/route.tsindex 2a835bef4e..7d2d618ce7 100644--- a/apps/web/app/(ee)/api/hubspot/callback/route.ts+++ b/apps/web/app/(ee)/api/hubspot/callback/route.ts@@ -8,10 +8,10 @@ import {} from "@/lib/integrations/hubspot/constants";import { hubSpotAuthTokenSchema } from "@/lib/integrations/hubspot/schema";import { installIntegration } from "@/lib/integrations/install";+import { WorkspaceProps } from "@/lib/types";import { redis } from "@/lib/upstash";import z from "@/lib/zod";import { prisma } from "@dub/prisma";-import { Project } from "@dub/prisma/client";import { getSearchParams } from "@dub/utils";import { redirect } from "next/navigation";@@ -25,7 +25,7 @@ const oAuthCallbackSchema = z.object({// GET /api/hubspot/callback - OAuth callback from HubSpotexport const GET = async (req: Request) => {const { searchParams } = new URL(req.url);- let workspace: Pick<Project, "id" | "slug" | "plan"> | null = null;+ let workspace: Pick<WorkspaceProps, "id" | "slug" | "users"> | null = null;// Local development redirect since the callback might be coming through ngrokif (@@ -68,10 +68,37 @@ export const GET = async (req: Request) => {select: {id: true,slug: true,- plan: true,+ users: {+ where: {+ userId: session.user.id,+ },+ select: {+ role: true,+ defaultFolderId: true,+ },+ },},});+ // Check if the user is a member of the workspace+ if (workspace.users.length === 0) {+ throw new DubApiError({+ code: "bad_request",+ message: "You are not a member of this workspace. ",+ });+ }++ // Check if the user is an owner of the workspace+ if (workspace.users[0].role !== "owner") {+ throw new DubApiError({+ code: "bad_request",+ message: "Only workspace owners can install integrations. ",+ });+ }++ // Delete the state key from Redis+ await redis.del(stateKey);+const body = new URLSearchParams({code,grant_type: "authorization_code",@@ -120,9 +147,6 @@ export const GET = async (req: Request) => {workspaceId,credentials,});-- // Delete the state key from Redis- await redis.del(stateKey);} catch (e: any) {return handleAndReturnErrorResponse(e);}