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

Enforce exp to be an Integer #205

Merged
merged 1 commit into from
Jul 11, 2017
Merged
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
2 changes: 1 addition & 1 deletion lib/jwt/encode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def encoded_header(algorithm, header_fields)
end

def encoded_payload(payload)
raise InvalidPayload, 'exp claim must be an integer' if payload && payload['exp'] && payload['exp'].is_a?(Time)
raise InvalidPayload, 'exp claim must be an integer' if payload && payload['exp'] && !payload['exp'].is_a?(Integer)
Encode.base64url_encode(JSON.generate(payload))
end

Expand Down
8 changes: 8 additions & 0 deletions spec/jwt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@
JWT.encode payload, nil, alg
end.to raise_error JWT::InvalidPayload
end

it 'should display a better error message if payload exp is not an Integer' do
payload['exp'] = Time.now.to_i.to_s

expect do
JWT.encode payload, nil, alg
end.to raise_error JWT::InvalidPayload
end
end

%w(HS256 HS512256 HS384 HS512).each do |alg|
Expand Down