Skip to content

Commit bb1e8b6

Browse files
committed
fix(mothership): verify workspace membership before resolving workspace branch
1 parent 7413b77 commit bb1e8b6

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

apps/sim/lib/copilot/chat/post.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { type Context as OtelContext, context as otelContextApi } from '@opentelemetry/api'
22
import { db } from '@sim/db'
3-
import { copilotChats } from '@sim/db/schema'
3+
import { copilotChats, permissions } from '@sim/db/schema'
44
import { createLogger } from '@sim/logger'
55
import { generateId } from '@sim/utils/id'
6-
import { eq, sql } from 'drizzle-orm'
6+
import { and, eq, sql } from 'drizzle-orm'
77
import { type NextRequest, NextResponse } from 'next/server'
88
import { z } from 'zod'
99
import { isZodError, validationErrorResponse } from '@/lib/api/server'
@@ -569,6 +569,22 @@ async function resolveBranch(params: {
569569
return createBadRequestResponse('workspaceId is required when workflowId is not provided')
570570
}
571571

572+
const [permissionRow] = await db
573+
.select({ permissionType: permissions.permissionType })
574+
.from(permissions)
575+
.where(
576+
and(
577+
eq(permissions.userId, authenticatedUserId),
578+
eq(permissions.entityType, 'workspace'),
579+
eq(permissions.entityId, requestedWorkspaceId)
580+
)
581+
)
582+
.limit(1)
583+
584+
if (!permissionRow) {
585+
return createBadRequestResponse('Workspace not found or access denied')
586+
}
587+
572588
return {
573589
kind: 'workspace',
574590
workspaceId: requestedWorkspaceId,

0 commit comments

Comments
 (0)