Skip to content

Commit 80c7061

Browse files
committed
fix(credentials): restrict credential creation to workspace admin
Write-only users could create secrets but got 'member' role, making them unable to edit/delete their own secrets. Now credential creation requires workspace admin permission, consistent with the role mapping.
1 parent 24eb310 commit 80c7061

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

apps/sim/app/api/credentials/route.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
ATLASSIAN_SERVICE_ACCOUNT_SECRET_TYPE,
3030
} from '@/lib/oauth/types'
3131
import { captureServerEvent } from '@/lib/posthog/server'
32-
import { checkWorkspaceAccess } from '@/lib/workspaces/permissions/utils'
32+
import { checkWorkspaceAccess, hasWorkspaceAdminAccess } from '@/lib/workspaces/permissions/utils'
3333

3434
const logger = createLogger('CredentialsAPI')
3535

@@ -296,8 +296,16 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
296296
} = parsed.data.body
297297

298298
const workspaceAccess = await checkWorkspaceAccess(workspaceId, session.user.id)
299-
if (!workspaceAccess.canWrite) {
300-
return NextResponse.json({ error: 'Write permission required' }, { status: 403 })
299+
if (!workspaceAccess.hasAccess) {
300+
return NextResponse.json({ error: 'Workspace access required' }, { status: 403 })
301+
}
302+
303+
const isAdmin = await hasWorkspaceAdminAccess(session.user.id, workspaceId)
304+
if (!isAdmin) {
305+
return NextResponse.json(
306+
{ error: 'Admin permission required to manage credentials' },
307+
{ status: 403 }
308+
)
301309
}
302310

303311
let resolvedDisplayName = displayName?.trim() ?? ''

0 commit comments

Comments
 (0)