Skip to content

Commit

Permalink
Added a type check on the token kid
Browse files Browse the repository at this point in the history
  • Loading branch information
bellebaum authored and anakinj committed Jan 31, 2023
1 parent bc80470 commit 00a2e31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/jwt/jwk/key_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def initialize(options)

def key_for(kid)
raise ::JWT::DecodeError, 'No key id (kid) found from token headers' unless kid || @allow_nil_kid
raise ::JWT::DecodeError, 'Invalid type for kid header parameter' unless kid.nil? || kid.is_a?(String)

jwk = resolve_key(kid)

Expand Down
9 changes: 9 additions & 0 deletions spec/jwk/decode_with_jwk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@
end
end

context 'when the token kid is not a string' do
let(:token_headers) { { kid: 5 } }
it 'raises an exception' do
expect { described_class.decode(signed_token, nil, true, { algorithms: ['RS512'], jwks: public_jwks }) }.to raise_error(
JWT::DecodeError, 'Invalid type for kid header parameter'
)
end
end

context 'mixing algorithms using kid header' do
let(:hmac_jwk) { JWT::JWK.new('secret') }
let(:rsa_jwk) { JWT::JWK.new(OpenSSL::PKey::RSA.new(2048)) }
Expand Down

0 comments on commit 00a2e31

Please sign in to comment.