Skip to content

Commit 175d608

Browse files
committed
refactor(copilot): gate attachment tracking with the shared permission predicate
`permissionSatisfies` is the documented single source of truth for permission comparisons and exists to replace hand-written `=== 'admin' || === 'write'` ladders. `userPermission` is typed `string` for legacy reasons, so narrow it with `isPermissionType` first — an unrecognized value fails the gate instead of ranking below every level. Behavior is unchanged for all three levels. Imported from the dependency-free `/predicates` subpath rather than `/workspace`, which would pull `@sim/db` onto the chat request path.
1 parent d88c822 commit 175d608

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { BrowserKnownSession } from '@sim/browser-protocol'
22
import { createLogger } from '@sim/logger'
3+
import { isPermissionType, permissionSatisfies } from '@sim/platform-authz/predicates'
34
import { toError } from '@sim/utils/errors'
45
import { LRUCache } from 'lru-cache'
56
import { getHighestPrioritySubscription } from '@/lib/billing/core/subscription'
@@ -338,10 +339,10 @@ export async function buildCopilotRequestPayload(
338339
// upload routes that issue these keys already require — reaching the chat
339340
// endpoint with `read` must not confer a file-write capability.
340341
const uploadContexts: Array<{ type: string; content: string; tag?: string; path?: string }> = []
341-
// `PermissionType` is exactly read | write | admin, so this covers the whole
342-
// write-or-better half of the ordering.
342+
// `userPermission` is typed `string` for legacy reasons, so narrow it before
343+
// comparing — an unrecognized value must fail the gate, not rank below it.
343344
const canWriteWorkspaceFiles =
344-
params.userPermission === 'write' || params.userPermission === 'admin'
345+
isPermissionType(params.userPermission) && permissionSatisfies(params.userPermission, 'write')
345346
if (chatId && params.workspaceId && fileAttachments && fileAttachments.length > 0) {
346347
if (!canWriteWorkspaceFiles) {
347348
logger.warn('Dropping chat file attachments without workspace write access', {

0 commit comments

Comments
 (0)