`JWTVerifier` answers 500 instead of 401 for a PS256 token when it verifies with an EC key (jwt < 3.3.0)
維護者通常 1 天內回覆
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 35/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 停滯
- 技術堆疊
- ruby
研究方向
Start with lib/mcp/server/oauth/jwt_verifier.rb at the algorithm configuration and verify rescue paths, then follow the middleware error handling in lib/mcp/server/oauth/middleware.rb. Reproduce with the provided EC key and PS256 token on jwt 3.2.0, then check the middleware response. Done when this case returns 401 invalid_token instead of 500; the issue requests regression coverage for key:, jwks: and jwks_uri:.
由索引模型根據 Issue 內容生成。
描述
JWTVerifier allows PS256, PS384 and PS512 together with ES256, ES384 and ES512 by default (jwt_verifier.rb:40), whatever the key type. With an EC key, a static EC JWKS or a fetched EC JWKS, a token whose header says alg: PS256 makes jwt 3.2.0 and earlier call verify_pss on the EC key. That raises NoMethodError.
JWTVerifier#verify rescues only jwt errors (jwt_verifier.rb:92-110). So OAuth::Middleware (middleware.rb:45-51) and the Streamable HTTP transport (streamable_http_transport.rb:2413-2418) answer 500 server_error and call the exception reporter, instead of 401 invalid_token. Any client can send such a token. It needs no key.
jwt 3.3.0 fixed the root cause in jwt/ruby-jwt#722: Ps#verify now raises JWT::VerificationKeyError for a non-RSA key. That class is a JWT::DecodeError, so with jwt 3.3.0 the same token gives InvalidTokenError. But docs/installation.md asks for gem "jwt" with no version, so applications on jwt 3.2.0 and earlier, including the 2.x line, still get 500.
Repro
Run from the repository root with bundle exec ruby -I lib repro.rb:
require "mcp"
require "jwt"
require "openssl"
require "base64"
metadata = MCP::Server::OAuth::ProtectedResourceMetadata.new(
resource: "https://mcp.example.com/mcp",
authorization_servers: ["https://as.example.com"],
)
verifier = MCP::Server::OAuth::JWTVerifier.new(
resource_metadata: metadata,
key: OpenSSL::PKey::EC.generate("prime256v1"),
)
header = { alg: "PS256", typ: "JWT" }
claims = { iss: "https://as.example.com", aud: "https://mcp.example.com/mcp", exp: Time.now.to_i + 600 }
token = [header, claims].map { |part| Base64.urlsafe_encode64(JSON.generate(part), padding: false) }.join(".") + ".AAAA"
puts "jwt #{JWT::VERSION::STRING}"
begin
verifier.verify(token)
rescue => e
puts "#{e.class}: #{e.message}"
end
Expected (and the result with jwt 3.3.0):
jwt 3.3.0
MCP::Server::OAuth::InvalidTokenError: Invalid token
Actual with jwt 3.2.0:
jwt 3.2.0
NoMethodError: undefined method 'verify_pss' for an instance of OpenSSL::PKey::EC
Passing an explicit algorithms: ["ES256"] avoids the problem.
Suggested fix
Any of these:
- Drop the algorithms that do not fit the configured key before calling
JWT.decode:RS*andPS*for RSA keys,ES*for EC keys,EdDSAfor Ed25519 keys. This works with every jwt version. - Require jwt 3.3.0 or later when
JWTVerifierloads, with a clear error, and document the minimum version.
Add a regression test for each key source (key:, jwks:, jwks_uri:) through the middleware.
- 主要語言
- Ruby
- 星號
- 940
- 分支
- 143
- 平均合併
- 1 天 3 小時
- 30 天內合併 PR
- 47
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/ruby-sdk 的其他 Issue
-
Invalid UTF-8 in `MCP-Protocol-Version`, `Mcp-Method` or `Mcp-Name` gives 500 instead of 400可能已有人在做 @atesgoral 今天認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 78/100
modelcontextprotocol/ruby-sdk#663 ·
維護者通常 1 天內回覆
-
`Client::Stdio` passes the whole parent environment to the server process可能已有人在做 @atesgoral 今天認領。 未關閉bug
難度 4/5 3-5 天 新手友好度 55/100
modelcontextprotocol/ruby-sdk#662 ·
維護者通常 1 天內回覆
-
Elicitation results are not checked against `requested_schema`, but the docs say they match it可能已有人在做 @atesgoral 今天認領。 未關閉bug
難度 3/5 1-2 天 新手友好度 35/100
modelcontextprotocol/ruby-sdk#661 ·
維護者通常 1 天內回覆
-
HTTP client sends handler exception messages back to the server可能已有人在做 @atesgoral 今天認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 35/100
modelcontextprotocol/ruby-sdk#660 ·
維護者通常 1 天內回覆
-
`logging/setLevel` from one session changes the log level of other sessions可能已有人在做 @atesgoral 今天認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 35/100
modelcontextprotocol/ruby-sdk#658 ·
維護者通常 1 天內回覆
查看 modelcontextprotocol/ruby-sdk 的全部 Issue
相似的 Issue
-
bug javascript
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 88/100
yegor256/netbout.rb#69 ·
-
難度 2/5 1-3 小時 新手友好度 84/100
yegor256/iccq.github.io#161 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
palladius/rails8-app-on-gcp#198 ·
-
bug
難度 1/5 1 小時以內 新手友好度 95/100
WikiEducationFoundation/WikiEduDashboard#7258 ·
維護者通常 1 天內回覆