Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport fix for CVE-2023-51774 from 1.16.6 to 1.15.x #122

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/json/jwt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ def decode_compact_serialized(jwt_string, key_or_secret, algorithms = nil, encry
when JWS::NUM_OF_SEGMENTS
JWS.decode_compact_serialized jwt_string, key_or_secret, algorithms, allow_blank_payload
when JWE::NUM_OF_SEGMENTS
JWE.decode_compact_serialized jwt_string, key_or_secret, algorithms, encryption_methods
if allow_blank_payload
raise InvalidFormat.new("JWE w/ blank payload is not supported.")
else
JWE.decode_compact_serialized jwt_string, key_or_secret, algorithms, encryption_methods
end
else
raise InvalidFormat.new("Invalid JWT Format. JWT should include #{JWS::NUM_OF_SEGMENTS} or #{JWE::NUM_OF_SEGMENTS} segments.")
end
Expand Down
8 changes: 8 additions & 0 deletions spec/json/jwt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,14 @@
end
end
end

context 'when JWE format (5 segments) and allow_blank_payload is true' do
it do
expect do
JSON::JWT.decode 'one.two.three.four.five', 'secret', nil, nil, true
end.to raise_error JSON::JWT::InvalidFormat
end
end
end

describe '.pretty_generate' do
Expand Down