fix(server): prevent MCP traffic from extending credentials
Problem
MCP credential liveness was refreshed by every successful bearer-authenticated request. Request activity could therefore keep a credential alive after its provider session stopped reporting liveness, defeating the 24-hour abandonment window.
Fix
- Track the last trusted provider activity separately as
lastProviderAliveAt. - Refresh credential liveness only when the credential is issued or a provider turn calls
touch(). - Keep
resolve()responsible for pruning and authentication without allowing bearer traffic to renew the credential. - Add regression coverage for the exact expiry boundary while preserving long-lived sessions that continue receiving provider turns.
Abandoned credentials now expire relative to the last trusted provider signal. Active provider sessions still remain valid across multiple liveness windows.
Verification
./node_modules/.bin/vp test run apps/server/src/mcp/McpSessionRegistry.test.ts apps/server/src/mcp/McpHttpServer.test.ts— 10 tests passed./node_modules/.bin/vp lint --type-aware --type-check --deny-warnings apps/server/src/mcp/McpSessionRegistry.ts apps/server/src/mcp/McpSessionRegistry.test.ts./node_modules/.bin/vp fmt --check apps/server/src/mcp/McpSessionRegistry.ts apps/server/src/mcp/McpSessionRegistry.test.tsgit diff --check
Model: OpenAI Codex (GPT-5.6); harness: Codex desktop.
[!NOTE]
Stop
McpSessionRegistry.resolvefrom refreshing credential livenessPreviously, resolving a bearer token updated
lastAliveAt, meaning ongoing MCP traffic could keep abandoned credentials alive indefinitely. Now only provider turns (viatouch) refresh the liveness timestamp, renamed tolastProviderAliveAtfor clarity. Behavioral Change: credentials now expire based on the last provider turn, not the last MCP request, so long-running MCP sessions with no provider activity will have their credentials pruned.Macroscope summarized fd5586d.
[!NOTE] High Risk Changes authentication liveness for
/mcpbearer tokens guarding the preview toolkit on remotely reachable servers; the fix tightens abandonment behavior but alters how long valid-looking tokens remain usable without provider activity.Overview MCP bearer credentials no longer stay alive from
/mcptraffic alone. Liveness is tracked aslastProviderAliveAtand is updated only on issue and providertouch(per turn), not whenresolveauthenticates a request.
resolvestill prunes expired records and returns the scope, but repeated bearer use cannot push out the abandonment window. That closes the gap where a dead provider session could keep preview toolkit access if something kept calling MCP with a stolen or leftover token.A regression test confirms that resolving near the window boundary does not extend life past the last provider signal, while existing coverage still expects long sessions to survive when
touchruns on each turn.Reviewed by Cursor Bugbot for commit fd5586d891304482b8a7a299c3e09f49f11036d3. Bugbot is set up for automated code reviews on this repo. Configure here.
[!IMPORTANT]
Review skipped
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
6f5a5113-46a0-4dbc-8029-2c5404083fa3You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- [ ] 🔍 Trigger review
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Approvability
Verdict: Needs human review
This PR modifies credential expiration behavior in security-sensitive session management code. Changes to authentication/credential lifetime logic warrant human review to verify the intended security posture.
You can customize Macroscope's approvability policy. Learn more.