Skip to content

Commit d26402b

Browse files
committed
fix(credentials): answer unsupported credential lookups before the access check
1 parent 1d9ac6a commit d26402b

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎apps/sim/app/api/auth/oauth/credentials/route.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ export const GET = withRouteHandler(async (request: NextRequest) => {
206206
platformCredential.workspaceId
207207
)
208208

209+
// Before any access check, so an unsupported credential reads the same as an unknown id.
210+
if (
211+
platformCredential.type !== 'service_account' &&
212+
(platformCredential.type !== 'oauth' || !platformCredential.accountId)
213+
) {
214+
return NextResponse.json({ credentials: [] }, { status: 200 })
215+
}
216+
209217
// A workflowId only pins the credential's workspace; membership is checked on every lookup.
210218
if (
211219
workflowId &&
@@ -246,10 +254,6 @@ export const GET = withRouteHandler(async (request: NextRequest) => {
246254
)
247255
}
248256

249-
if (platformCredential.type !== 'oauth' || !platformCredential.accountId) {
250-
return NextResponse.json({ credentials: [] }, { status: 200 })
251-
}
252-
253257
// permission-group-enforced: integrations.manage — the credentialId path carries its own workspace scope
254258
if (await credentialScopeWithheld()) {
255259
return NextResponse.json(

‎apps/sim/lib/credentials/application/single-credential-lookup.integration.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ describe('GET /api/auth/oauth/credentials by credentialId', () => {
175175
})
176176
})
177177

178+
it('answers a non-member about an unsupported credential exactly as about an unknown id', async () => {
179+
const unknown = await lookupOAuth(outsiderId, { credentialId: generateId(), workflowId })
180+
expect(unknown).toEqual({ status: 200, names: [] })
181+
expect(
182+
await lookupOAuth(outsiderId, { credentialId: personalEnvCredentialId, workflowId })
183+
).toEqual(unknown)
184+
})
185+
178186
it.each([
179187
['a credential member', memberId],
180188
['a workspace admin', adminId],

0 commit comments

Comments
 (0)