JWT::EncodedToken calls key_finder before checking the token's algorithm
Maintainer thường phản hồi trong vòng 1 ngày
Đá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ả
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
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của jwt/ruby-jwt
-
JWT::EncodedToken raises TypeError for a non-object headerCó thể đã có người làm @anakinj đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
jwt/ruby-jwt#780 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
JWT::EncodedToken accepts tokens with more than three segmentsCó thể đã có người làm @anakinj đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 30/100
jwt/ruby-jwt#779 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
jwt/ruby-jwt#743 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
jwt/ruby-jwt#723 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
feature
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
jwt/ruby-jwt#428 · 7 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
zold-io/zold-ruby-sdk#85 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày