JWT::EncodedToken accepts tokens with more than three segments

未关闭
#779 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@anakinj 已经在做这个了。

开始于 2026年11月2日。

  • #782 来自 @anakinj —— 未关闭

评估

难度
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 内容生成。

描述

bug

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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

jwt/ruby-jwt 的其他 Issue

查看 jwt/ruby-jwt 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。