Repository navigation
feat(server_runtime): refuse MCP session tokens older than mcp_token_max_age_seconds - #6782
Closed
d-molinari wants to merge 1 commit into
Closed
d-molinari wants to merge 1 commit into
d-molinari wants to merge 1 commit into
Conversation
…max_age_seconds MCP session tokens were signed with URLSafeSerializer, which carries no timestamp, so a token stayed valid as long as the server accepted its session. Code in a sandbox that reads a token could use it after its episode. Tokens are now signed with URLSafeTimedSerializer. A resources server that sets mcp_token_max_age_seconds answers a request to /mcp whose token is older with HTTP 401 and the OAuth invalid_token error, before the MCP SDK reads it; with mcp_bearer_token the reply also carries the RFC 6750 WWW-Authenticate challenge. The checkpoint middleware, which runs first, reads such a token as one that does not verify and leaves it to the endpoint. Session routing still sends it to its session's worker, whose endpoint refuses it. The option is off by default, and a token is then accepted at any age, as before. A token signed after now, which a step back of the host clock makes, is not refused. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Daniele Molinari <[email protected]>
7 tasks done
Contributor
Author
Closed
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Lets a resources server refuse MCP session tokens older than a limit. This is the follow-up promised in #6161's review:
URLSafeSerializercarries no timestamp, so a token stays valid as long as the server accepts its session, and code that reads one in a sandbox can use it after its episode.URLSafeTimedSerializer, so each carries the second its seed signed it.mcp_token_max_age_seconds(needsexpose_tools_over_mcp). A request to/mcpwhose token is older is answered before the MCP SDK reads it: HTTP 401 with{"error": "invalid_token", "error_description": ...}, the reply the SDK's own bearer authentication gives. Withmcp_bearer_tokenit also carriesWWW-Authenticate: Bearer error="invalid_token", ...(RFC 6750) and names no framework. No tool runs.max_age, which refuses negative ages.Validation
On Linux (aarch64, Python 3.13), at this commit (
uv sync --extra dev):tests/unit_tests/server_runtime/{test_mcp_auto_exposure,test_checkpoint_resources,test_checkpoint_resources_mcp,test_session_routing,test_base_server,test_episode_tokens,test_checkpoint_participant_workers}.py: 565 passed.The new tests on main's
nemo_gym/server_runtime: each fails. The two "no limit: any age is served" controls pass on both, as they should.Mutants, each failing its test:
expose_tools_over_mcp;CI-equivalent gate: core shards 0-3 with coverage (6,454 / 5,750 / 6,318 / 6,246 passed),
-m sandbox(2,103 passed),combine_core_coverage.py: 95.10%.Server suites of every component that exposes MCP or reads its token:
example_mcp_weather,workplace_assistant,agentic_mme,hle_web_tools,rna_design,openenv,newton_bench,interactive_browser,gdpval,equivalence_llm_judge;single_agent_turn;claude_code_agent,codex_agent,hermes_agent,haystack_agent,pi_sandboxed_agent,opencode_sandboxed_agent,nemo_fabric_agent,harness_agent;officeenvwith OfficeEnv 1.10.0.All passed except
interactive_browser's 6local_playwrightbackend tests. They need a Chromium that host lacks, and they fail the same way with main'snemo_gym.tests/e2e/session_routing(NEMO_GYM_MULTIWORKER_E2E=1), 3 runs: 3/3 passed each.pre-commit run --fileson the 7 changed files: passed.Rollouts
N/A: no environment or agent behavior changes unless a config sets the new option, and none in this repo does.
Compatibility and benchmark impact
None for existing configs. The option is off by default, and a token of any age is then served as before. The token format changes (it gains a timestamp), but only the server that signed a token reads it.
Checklist
git commit -s) (so the DCO check passes).🤖 Generated with Claude Code