Skip to content

Commit bc097f2

Browse files
committed
fix(cloud-agent-next): fail closed on GitLab access revocation
Access-revocation reasons (no_integration_found, invalid_org_id) now throw BAD_REQUEST instead of falling back to the stored token, so the session cannot keep using a managed GitLab token after the integration or org access was removed. Transient failures retain the last-known token fallback.
1 parent e7347e4 commit bc097f2

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

services/cloud-agent-next/src/persistence/CloudAgentSession.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,10 +2271,15 @@ export class CloudAgentSession extends DurableObject<WorkerEnv> {
22712271

22722272
/**
22732273
* Refresh a managed GitLab token via GIT_TOKEN_SERVICE. Logs and returns
2274-
* the current value if the refresh fails so callers can keep running with
2275-
* the last-known token (best effort). Successful refreshes are persisted
2276-
* to metadata so a later refresh failure falls back to the most recent
2277-
* working token rather than a stale prepare-time token.
2274+
* the current value if the refresh fails with a transient reason so callers
2275+
* can keep running with the last-known token (best effort). Successful
2276+
* refreshes are persisted to metadata so a later refresh failure falls back
2277+
* to the most recent working token rather than a stale prepare-time token.
2278+
*
2279+
* Access-revocation reasons (`no_integration_found`, `invalid_org_id`) fail
2280+
* closed by throwing `BAD_REQUEST`: the stored token is no longer authorized
2281+
* (integration was removed, or user lost access to the org) and continuing
2282+
* to use it would bypass revocation.
22782283
*
22792284
* `gitlabTokenManaged === false` (explicitly set during prepare when the
22802285
* caller supplied their own PAT) skips refresh. `undefined` — i.e. sessions
@@ -2299,6 +2304,12 @@ export class CloudAgentSession extends DurableObject<WorkerEnv> {
22992304
}
23002305
return result.token;
23012306
}
2307+
if (result.reason === 'no_integration_found' || result.reason === 'invalid_org_id') {
2308+
throw new TRPCError({
2309+
code: 'BAD_REQUEST',
2310+
message: 'No GitLab integration found. Please connect your GitLab account first.',
2311+
});
2312+
}
23022313
logger
23032314
.withFields({ reason: result.reason, sessionId: metadata.sessionId })
23042315
.warn('Managed GitLab token refresh failed; using last-known value');

0 commit comments

Comments
 (0)