JWT::EncodedToken calls key_finder before checking the token's algorithm

Đang mở
#781 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@anakinj đang làm issue này rồi.

Từ ngày 2/11/2026.

  • #784 của @anakinj — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
ruby, security
Lĩnh vực
authentication, security

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement

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.

Ngôn ngữ chính
Ruby
Star
3.7k
Fork
381
Merge trung bình
19 giờ 13 phút
Pull request đã merge (30 ngày)
8

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của jwt/ruby-jwt

Tất cả issue của jwt/ruby-jwt

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.