Skip to content

Fix versioned auth middleware checks - #4401

Merged
jlowin merged 2 commits into
mainfrom
codex/ghsa-rmq9-jm55-jxgc
Jun 28, 2026
Merged

Fix versioned auth middleware checks#4401
jlowin merged 2 commits into
mainfrom
codex/ghsa-rmq9-jm55-jxgc

Conversation

@jlowin

@jlowin jlowin commented Jun 27, 2026

Copy link
Copy Markdown
Member

FastMCP carries requested component versions in _meta.fastmcp.version, but direct server execution rebuilds the middleware request params before authorization runs. That meant middleware could resolve a same-named component without the version metadata that execution would later use. This preserves FastMCP version metadata on synthetic tools/call, resources/read, and prompts/get params, then has AuthMiddleware authorize the same versioned component that will execute.

await client.call_tool("calc", {}, version="1.0")

The request metadata now remains visible through middleware, so the auth check and execution both resolve calc@1.0 instead of evaluating different versions of the same component.

@jlowin
jlowin marked this pull request as ready for review June 27, 2026 16:31
@marvin-context-protocol marvin-context-protocol Bot added server Related to FastMCP server implementation or server-side functionality. auth Related to authentication (Bearer, JWT, OAuth, WorkOS) for client or server. bugs labels Jun 27, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃挕 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 840374e1ad

鈩癸笍 About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 馃憤.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread fastmcp_slim/fastmcp/server/server.py Outdated
Comment on lines +107 to +108
if version is None or version.eq is None:
return None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve range version specs in auth metadata

When callers use the public server API with a non-exact VersionSpec such as VersionSpec(lt="2.0"), this branch drops the version metadata, so AuthMiddleware authorizes the default/highest component while execution still uses the original range. In a server with public calc@2.0 and admin-tagged calc@1.0, await mcp.call_tool("calc", {}, version=VersionSpec(lt="2.0")) runs the restricted v1 after checking v2. The synthetic middleware request needs to carry the full VersionSpec, or auth needs another way to use the same spec as execution.

Useful? React with 馃憤聽/ 馃憥.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃挕 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 840374e1ad

鈩癸笍 About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 馃憤.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread fastmcp_slim/fastmcp/server/server.py Outdated
Comment on lines +107 to +108
if version is None or version.eq is None:
return None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve non-exact version specs for auth

When a direct server caller passes a range such as VersionSpec(lt="2.0"), this helper drops the version metadata entirely, so AuthMiddleware authorizes the default/highest component while the subsequent call_next still executes with the original range. In a server with public calc@2.0 and admin-tagged calc@1.0, await mcp.call_tool("calc", {}, version=VersionSpec(lt="2.0")) authorizes against 2.0 but runs 1.0, leaving the versioned auth bypass in place for range specs.

Useful? React with 馃憤聽/ 馃憥.

@jlowin
jlowin merged commit de521e6 into main Jun 28, 2026
13 checks passed
@jlowin
jlowin deleted the codex/ghsa-rmq9-jm55-jxgc branch June 28, 2026 14:43
@jlowin jlowin added the bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. label Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth Related to authentication (Bearer, JWT, OAuth, WorkOS) for client or server. bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. server Related to FastMCP server implementation or server-side functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant