JWT::EncodedToken calls key_finder before checking the token's algorithm
メンテナーはふだん 1 日以内に返信
関連するプルリクエストがすでにマージされています。
- #784 @anakinj による — マージ済み
評価
- 難易度
- 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
- 平均マージ
- 17時間 10分
- マージ済み PR(30日)
- 11
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
jwt/ruby-jwt のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 15/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
メンテナーはふだん 1 日以内に返信
-
feature
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
jwt/ruby-jwt#428 · コメント 7 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement feature help wanted up for grabs
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
jwt/ruby-jwt#80 · コメント 11 件 · リアクション 8 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
riverqueue/river#1576 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
TheOdinProject/curriculum#31512 ·
メンテナーはふだん 1 日以内に返信