JWT::EncodedToken accepts tokens with more than three segments
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 30/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- ruby
调研方向
Start in lib/jwt/encoded_token.rb, where EncodedToken#initialize splits the token with jwt.split('.') and keeps only the first three parts, then compare it with JWT::Decode#validate_segment_count!. Pull request #782 is already open against this issue, so check it before starting. Done means EncodedToken raises JWT::MalformedTokenError for tokens with extra segments while tokens with an empty detached payload still verify.
由索引模型根据 Issue 内容生成。
描述
JWT.decode rejects tokens with extra segments, but JWT::EncodedToken ignores anything after the third one. A valid token with junk appended therefore verifies.
This isn't a forgery, because the signature still has to match, but the two APIs disagree on what a valid token is, and the token string is malleable.
rsa = OpenSSL::PKey::RSA.generate(2048)
token = "#{JWT.encode({ 'sub' => 'x' }, rsa, 'RS256')}.extra"
JWT::EncodedToken.new(token).verify_signature!(algorithm: 'RS256', key: rsa.public_key)
# => nil (accepted)
JWT.decode(token, rsa.public_key, true, algorithm: 'RS256')
# => JWT::MalformedTokenError: Not enough or too many segments
Reproduced on 3.3.1. lib/jwt/encoded_token.rb is unchanged on main.
Cause: EncodedToken#initialize uses jwt.split('.') and keeps the first three parts. The segment count check only exists in JWT::Decode#validate_segment_count!.
Suggestion: Raise JWT::MalformedTokenError for tokens with too many segments when using EncodedToken, without breaking tokens that have an empty detached payload.
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 于 1 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
jwt/ruby-jwt#780 · 1 个 reaction ·
维护者通常 1 天内回复
-
JWT::EncodedToken calls key_finder before checking the token's algorithm可能已有人在做 @anakinj 于 1 天前认领。 未关闭enhancement
难度 3/5 半天 新手友好度 42/100
jwt/ruby-jwt#781 · 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 ·
-
难度 2/5 半天 新手友好度 72/100
shakacode/react-on-rails-demo-flagship#102 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
akitaonrails/ai-book-2026#12 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
openfoodfoundation/openfoodnetwork#14970 ·
维护者通常 1 天内回复