t3code icon indicating copy to clipboard operation
t3code copied to clipboard

fix(server): prevent MCP traffic from extending credentials

Open Lucenx9 opened this issue 4 months ago • 2 comments

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.ts
  • git diff --check

Model: OpenAI Codex (GPT-5.6); harness: Codex desktop.

[!NOTE]

Stop McpSessionRegistry.resolve from refreshing credential liveness

Previously, resolving a bearer token updated lastAliveAt, meaning ongoing MCP traffic could keep abandoned credentials alive indefinitely. Now only provider turns (via touch) refresh the liveness timestamp, renamed to lastProviderAliveAt for 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 /mcp bearer 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 /mcp traffic alone. Liveness is tracked as lastProviderAliveAt and is updated only on issue and provider touch (per turn), not when resolve authenticates a request.

resolve still 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 touch runs on each turn.

Reviewed by Cursor Bugbot for commit fd5586d891304482b8a7a299c3e09f49f11036d3. Bugbot is set up for automated code reviews on this repo. Configure here.

Lucenx9 avatar Jul 31 '26 13:07 Lucenx9

[!IMPORTANT]

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6f5a5113-46a0-4dbc-8029-2c5404083fa3

You can disable this status message by setting the reviews.review_status to false in 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot] avatar Jul 31 '26 13:07 coderabbitai[bot]

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.

macroscopeapp[bot] avatar Jul 31 '26 13:07 macroscopeapp[bot]