Skip to content

Commit

Permalink
Fix NoMethodError when a 2 segment token is missing 'alg' header
Browse files Browse the repository at this point in the history
  • Loading branch information
cmrd-senya committed Jul 15, 2022
1 parent b79e4b5 commit 0eb6e1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/jwt/decode.rb
Expand Up @@ -113,6 +113,8 @@ def segment_length
end

def none_algorithm?
return false unless algorithm.respond_to? :casecmp

algorithm.casecmp('none').zero?
end

Expand Down
9 changes: 9 additions & 0 deletions spec/jwt_spec.rb
Expand Up @@ -6,6 +6,7 @@
let :data do
data = {
:empty_token => 'e30K.e30K.e30K',
:empty_token_2_segment => 'e30K.e30K.',
:secret => 'My$ecretK3y',
:rsa_private => OpenSSL::PKey.read(File.read(File.join(CERT_PATH, 'rsa-2048-private.pem'))),
:rsa_public => OpenSSL::PKey.read(File.read(File.join(CERT_PATH, 'rsa-2048-public.pem'))),
Expand Down Expand Up @@ -537,6 +538,14 @@
JWT.decode data[:empty_token]
end.to raise_error JWT::IncorrectAlgorithm
end

context '2-segment token' do
it 'should raise JWT::IncorrectAlgorithm' do
expect do
JWT.decode data[:empty_token_2_segment]
end.to raise_error JWT::DecodeError
end
end
end
end

Expand Down

0 comments on commit 0eb6e1f

Please sign in to comment.