JWT::EncodedToken raises TypeError for a non-object header
维护者通常 1 天内回复
已经有一个关联 PR 被合并了。
- #783 来自 @anakinj —— 已合并
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- ruby
调研方向
从 lib/jwt/encoded_token.rb 开始,其中 valid_signature? 在没有检查解码后的 header 是否为 Hash 的情况下读取 header['alg']。与 JWT::Decode#verify_algo 中的检查进行比较,并使用 issue 中的代码片段复现,以查看原始的 TypeError。当非对象的 header 使 verify_signature! 抛出 JWT::MalformedTokenError,并且在现有的编码令牌测试旁边添加了回归测试时,即为完成。
由索引模型根据 Issue 内容生成。
描述
If a token's header is valid JSON but not an object, JWT::EncodedToken#verify_signature! raises a raw TypeError instead of a JWT error. Applications that rescue JWT errors won't catch it, so untrusted input could produce a 500 rather than a 401. JWT.decode handles the same token correctly.
rsa = OpenSSL::PKey::RSA.generate(2048)
b64 = ->(value) { JWT::Base64.url_encode(value) }
token = "#{b64.call('[]')}.#{b64.call('{}')}.#{b64.call('x')}"
JWT::EncodedToken.new(token).verify_signature!(algorithm: 'RS256', key: rsa.public_key)
# => TypeError: no implicit conversion of String into Integer
JWT.decode(token, rsa.public_key, true, algorithm: 'RS256')
# => JWT::MalformedTokenError: Token header not a JSON object
Reproduced on 3.3.1. lib/jwt/encoded_token.rb is unchanged on main.
Cause: EncodedToken#valid_signature? reads header['alg'] without checking that the header is a Hash. JWT::Decode#verify_algo has that check.
Suggestion: Raise JWT::MalformedTokenError when the decoded header isn't an object, covering valid_signature? and any other direct header[...] access on this path.
Posted by Claude on behalf of @anakinj.
- 主要语言
- Ruby
- 星标
- 3.7k
- 派生
- 381
- 平均合并
- 14 小时 13 分钟
- 30 天内合并 PR
- 13
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
jwt/ruby-jwt 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 65/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 15/100
维护者通常 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
-
internal product:ai-gateway size: S
难度 2/5 1-3 小时 新手友好度 67/100
Kong/developer.konghq.com#7931 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
rails/rails-dom-testing#136 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
nesquena/steward-os#79 ·
维护者通常 1 天内回复
-
area/tech debt
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
simp/pupmod-simp-sudo#166 ·
维护者通常 1 天内回复