JWT::EncodedToken calls key_finder before checking the token's algorithm
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 半天
- 新手友好度
- 42/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- ruby, security
调研方向
The bug sits in lib/jwt/encoded_token.rb: in valid_signature?, key_finder.call(self) runs before the verifiers are built from the allowed algorithms. Reproduce with the snippet in the issue, which should show the finder called once before JWT::VerificationError. Done means a disallowed alg raises JWT::IncorrectAlgorithm without calling the finder, while JWK-supplied algorithm calls still pass the existing specs.
由索引模型根据 Issue 内容生成。
描述
JWT.decode rejects a token with a disallowed alg before looking up a key. JWT::EncodedToken#verify_signature! calls key_finder first, so tokens that could never pass still trigger the lookup.
Signature verification still fails correctly, so this isn't a bypass. The concern is that key finders often fetch a remote JWKS, which lets an unauthenticated alg: none or HS256 token cause outbound requests when the application expects only RS256.
rsa = OpenSSL::PKey::RSA.generate(2048)
token = JWT.encode({ 'sub' => 'x' }, 'secret', 'HS256')
calls = 0
finder = lambda { |_token|
calls += 1
rsa.public_key
}
JWT::EncodedToken.new(token).verify_signature!(algorithm: 'RS256', key_finder: finder)
# => JWT::VerificationError: Signature verification failed (calls == 1)
JWT.decode(token, nil, true, algorithm: 'RS256') { |_header| rsa.public_key }
# => JWT::IncorrectAlgorithm: Expected a different algorithm (block not called)
Reproduced on 3.3.1, and an alg: none token behaves the same way. lib/jwt/encoded_token.rb is unchanged on main.
Cause: EncodedToken#valid_signature? evaluates key_finder.call(self) before creating the verifiers from the allowed algorithms.
Suggestion: When algorithm: is given, check the token's alg against it before calling key_finder, and raise JWT::IncorrectAlgorithm if it isn't allowed. Calls that rely on a JWK to supply the algorithm would need to keep working.
Posted by Claude on behalf of @anakinj.
- 主要语言
- Ruby
- 星标
- 3.7k
- 派生
- 381
- 平均合并
- 19 小时 13 分钟
- 30 天内合并 PR
- 8
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
jwt/ruby-jwt 的其他 Issue
-
JWT::EncodedToken raises TypeError for a non-object header可能已有人在做 @anakinj 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
jwt/ruby-jwt#780 · 1 个 reaction ·
维护者通常 1 天内回复
-
JWT::EncodedToken accepts tokens with more than three segments可能已有人在做 @anakinj 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 30/100
jwt/ruby-jwt#779 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 68/100
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 25/100
维护者通常 1 天内回复
-
feature
难度 5/5 一周以上 新手友好度 35/100
jwt/ruby-jwt#428 · 7 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
相似的 Issue
-
area/web interface
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
rubys/roundhouse#1757 ·
-
难度 1/5 1 小时以内 新手友好度 88/100
akitaonrails/ai-book-2026#12 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
openfoodfoundation/openfoodnetwork#14970 ·
维护者通常 1 天内回复
-
难度 2/5 1 小时以内 新手友好度 70/100
维护者通常 1 天内回复