fix: fail open when whoami resolves without a role

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L99mAR4LitqTcYY1Kn1ATH
This commit is contained in:
AlexRV12
2026-09-09 14:27:23 +02:00
co-authored by Claude Opus 5
parent 5f7ec4e2c0
commit c5e4d0100e
2 changed files with 12 additions and 2 deletions
@@ -83,4 +83,10 @@ describe('resolveSessionAccess', () => {
expect(access.capabilities.has('write_draft')).toBe(true)
expect(access.capabilities.has('deploy')).toBe(true)
})
it('fails open on a body that resolves without a role, rather than throwing', async () => {
whoami.mockResolvedValueOnce(undefined)
const access = await resolveSessionAccess('ws')
expect(access.capabilities.has('write_draft')).toBe(true)
})
})
@@ -42,10 +42,14 @@ export function hasCapabilities(
}
export async function resolveSessionAccess(workspace: string): Promise<SessionAccess> {
let me: User
let me: User | undefined
try {
me = await UserService.whoami({ workspace })
} catch {
} catch {}
// Checked rather than trusted: a body that arrives malformed resolves without
// throwing, and reading a capability off it would surface as a TypeError thrown
// out of the send rather than as the fail-open this whole path promises.
if (!me) {
return fullSessionAccess(workspace)
}