jwt 3.3.0 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/CONTRIBUTING.md +15 -3
- data/lib/jwt/claims/expiration.rb +4 -1
- data/lib/jwt/claims/not_before.rb +4 -1
- data/lib/jwt/decode.rb +0 -7
- data/lib/jwt/encoded_token.rb +25 -1
- data/lib/jwt/jwk/ec.rb +3 -1
- data/lib/jwt/jwk/key_base.rb +4 -0
- data/lib/jwt/jwk/set.rb +1 -5
- data/lib/jwt/version.rb +1 -1
- data/lib/jwt/x5c_key_finder.rb +7 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ac94f7fd1bb89ec71d44706775828e684817f608314d89021ff542c16783b2bd
|
|
4
|
+
data.tar.gz: 67a7a4b461307cc2605af71d5dfb5dad3eac48ffe9090bb76452774395ea4a24
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ef43ab8d9418b3eb5f36de01e18a461890f1c2d652a49544e167bf65c8fba51a39f306c9e702046ed7e39c73024111ecce7b737c0df63c2ce2164268eecf488c
|
|
7
|
+
data.tar.gz: c77ce20c2e1c03ac70ac59aae2a0e8d43c4ed5fcde37839c1c76ca872e83233e0a1a3fbe1ceff6e79212d9e77e47bd8feec73461c05682249655729cb9d41acc
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [v3.3.1](https://github.com/jwt/ruby-jwt/tree/v3.3.1) (2026-11-24)
|
|
4
|
+
|
|
5
|
+
[Full Changelog](https://github.com/jwt/ruby-jwt/compare/v3.3.0...v3.3.1)
|
|
6
|
+
|
|
7
|
+
**Fixes and enhancements:**
|
|
8
|
+
|
|
9
|
+
- Test that `JWT::Claims::Required` raises `JWT::MissingRequiredClaim` for a non-Hash payload [#768](https://github.com/jwt/ruby-jwt/pull/768) ([@renanmpimentel](https://github.com/renanmpimentel))
|
|
10
|
+
- Ignore unsupported `kty` values when a `JWT::JWK::Set` is built from an array [#744](https://github.com/jwt/ruby-jwt/pull/744) ([@RalphBragg](https://github.com/RalphBragg))
|
|
11
|
+
- Redact private JWK material from inspection [#754](https://github.com/jwt/ruby-jwt/pull/754) - [@OskarEichler](https://github.com/OskarEichler)
|
|
12
|
+
- Reject tokens with too many segments in `JWT::EncodedToken` signature verification [#782](https://github.com/jwt/ruby-jwt/pull/782) ([@anakinj](https://github.com/anakinj))
|
|
13
|
+
- Raise `JWT::MalformedTokenError` for a token header that is not a JSON object, including a string header in `JWT.decode` without verification [#783](https://github.com/jwt/ruby-jwt/pull/783) ([@anakinj](https://github.com/anakinj))
|
|
14
|
+
- Do not call the `key_finder` of `JWT::EncodedToken` when the token's algorithm is not allowed, so a mismatched `alg` header no longer verifies with a key finder [#784](https://github.com/jwt/ruby-jwt/pull/784) ([@anakinj](https://github.com/anakinj))
|
|
15
|
+
- Accept the RFC 8812 curve name `secp256k1` when importing EC JWKs, alongside `P-256K` [#787](https://github.com/jwt/ruby-jwt/pull/787) ([@anakinj](https://github.com/anakinj))
|
|
16
|
+
- Raise `JWT::JWKError` instead of `OpenSSL::PKey::EC::Point::Error` for EC JWK coordinates that are not a point on the given curve [#789](https://github.com/jwt/ruby-jwt/pull/789) ([@anakinj](https://github.com/anakinj))
|
|
17
|
+
- Raise `JWT::MalformedTokenError` for a malformed `x5c` header parameter instead of a raw Ruby exception [#740](https://github.com/jwt/ruby-jwt/pull/740) - [@arpitjain099](https://github.com/arpitjain099).
|
|
18
|
+
- Reject `nbf` and `exp` claims that are not finite numbers with `JWT::InvalidPayload` when decoding, including numeric strings ([GHSA-gp6v-qjfx-hrxc](https://github.com/jwt/ruby-jwt/security/advisories/GHSA-gp6v-qjfx-hrxc))
|
|
19
|
+
|
|
3
20
|
## [v3.3.0](https://github.com/jwt/ruby-jwt/tree/v3.3.0) (2026-09-11)
|
|
4
21
|
|
|
5
22
|
[Full Changelog](https://github.com/jwt/ruby-jwt/compare/v3.2.0...v3.3.0)
|
data/CONTRIBUTING.md
CHANGED
|
@@ -90,9 +90,21 @@ git push origin fix-a-little-problem -f
|
|
|
90
90
|
|
|
91
91
|
## Releasing a new version
|
|
92
92
|
|
|
93
|
-
The version
|
|
94
|
-
|
|
93
|
+
The version follows [Semantic Versioning](http://semver.org/) and lives in the [version.rb](lib/jwt/version.rb) file. It is bumped right after every release, so main normally already carries the next version number. Check that it is the number you mean to release and adjust it if, say, a feature landed on what had been set up as a patch release.
|
|
94
|
+
|
|
95
|
+
Prepare the release on a branch: give the upcoming [CHANGELOG](CHANGELOG.md) section its release date and remove the `Your contribution here` placeholders. Merge it as usual.
|
|
96
|
+
|
|
97
|
+
Then tag the merged commit and push the tag to this repository:
|
|
95
98
|
|
|
96
99
|
```bash
|
|
97
|
-
|
|
100
|
+
git checkout main
|
|
101
|
+
git pull upstream main
|
|
102
|
+
git tag -a v3.3.0 -m "Version 3.3.0"
|
|
103
|
+
git push upstream v3.3.0
|
|
98
104
|
```
|
|
105
|
+
|
|
106
|
+
Pushing the tag is what publishes the gem. The [push_gem.yml](.github/workflows/push_gem.yml) workflow verifies that the tag matches `JWT.gem_version`, builds the gem, pushes it to RubyGems using trusted publishing and waits for it to propagate. No RubyGems credentials are needed on your machine.
|
|
107
|
+
|
|
108
|
+
Do not use `rake release`. It builds and pushes the gem from your machine, which bypasses trusted publishing, and it pushes the tag too, so the workflow then fails trying to publish a version that already exists.
|
|
109
|
+
|
|
110
|
+
Once the workflow is green, [create a GitHub release](https://github.com/jwt/ruby-jwt/releases/new) for the tag, named `jwt-<version>` and with the changelog section for that version as its body. Finally, open the next iteration by bumping the version and adding a fresh `NEXT` changelog section.
|
|
@@ -16,12 +16,15 @@ module JWT
|
|
|
16
16
|
# @param context [Object] the context containing the JWT payload.
|
|
17
17
|
# @param _args [Hash] additional arguments (not used).
|
|
18
18
|
# @raise [JWT::ExpiredSignature] if the token has expired.
|
|
19
|
+
# @raise [JWT::InvalidPayload] if the 'exp' claim is not a finite number.
|
|
19
20
|
# @return [nil]
|
|
20
21
|
def verify!(context:, **_args)
|
|
21
22
|
return unless context.payload.is_a?(Hash)
|
|
22
23
|
return unless context.payload.key?('exp')
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
exp = context.payload['exp']
|
|
26
|
+
raise JWT::InvalidPayload, 'exp claim must be a finite Numeric value' unless exp.is_a?(::Numeric) && exp.finite?
|
|
27
|
+
raise JWT::ExpiredSignature, 'Signature has expired' if exp.to_i <= (Time.now.to_i - leeway)
|
|
25
28
|
end
|
|
26
29
|
|
|
27
30
|
private
|
|
@@ -16,12 +16,15 @@ module JWT
|
|
|
16
16
|
# @param context [Object] the context containing the JWT payload.
|
|
17
17
|
# @param _args [Hash] additional arguments (not used).
|
|
18
18
|
# @raise [JWT::ImmatureSignature] if the 'nbf' claim has not been reached.
|
|
19
|
+
# @raise [JWT::InvalidPayload] if the 'nbf' claim is not a finite number.
|
|
19
20
|
# @return [nil]
|
|
20
21
|
def verify!(context:, **_args)
|
|
21
22
|
return unless context.payload.is_a?(Hash)
|
|
22
23
|
return unless context.payload.key?('nbf')
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
nbf = context.payload['nbf']
|
|
26
|
+
raise JWT::InvalidPayload, 'nbf claim must be a finite Numeric value' unless nbf.is_a?(::Numeric) && nbf.finite?
|
|
27
|
+
raise JWT::ImmatureSignature, 'Signature nbf has not been reached' if nbf.to_i > (Time.now.to_i + leeway)
|
|
25
28
|
end
|
|
26
29
|
|
|
27
30
|
private
|
data/lib/jwt/decode.rb
CHANGED
|
@@ -58,7 +58,6 @@ module JWT
|
|
|
58
58
|
|
|
59
59
|
def verify_algo
|
|
60
60
|
raise JWT::IncorrectAlgorithm, 'An algorithm must be specified' if allowed_algorithms.empty?
|
|
61
|
-
raise JWT::MalformedTokenError, 'Token header not a JSON object' unless valid_token_header?
|
|
62
61
|
raise JWT::IncorrectAlgorithm, 'Token is missing alg header' unless alg_in_header
|
|
63
62
|
raise JWT::IncorrectAlgorithm, 'Expected a different algorithm' if allowed_and_valid_algorithms.empty?
|
|
64
63
|
end
|
|
@@ -113,15 +112,9 @@ module JWT
|
|
|
113
112
|
end
|
|
114
113
|
|
|
115
114
|
def none_algorithm?
|
|
116
|
-
return false unless valid_token_header?
|
|
117
|
-
|
|
118
115
|
alg_in_header == 'none'
|
|
119
116
|
end
|
|
120
117
|
|
|
121
|
-
def valid_token_header?
|
|
122
|
-
token.header.is_a?(Hash)
|
|
123
|
-
end
|
|
124
|
-
|
|
125
118
|
def alg_in_header
|
|
126
119
|
token.header['alg']
|
|
127
120
|
end
|
data/lib/jwt/encoded_token.rb
CHANGED
|
@@ -51,8 +51,11 @@ module JWT
|
|
|
51
51
|
# Returns the decoded header of the JWT token.
|
|
52
52
|
#
|
|
53
53
|
# @return [Hash] the header.
|
|
54
|
+
# @raise [JWT::MalformedTokenError] if the header is not a JSON object.
|
|
54
55
|
def header
|
|
55
|
-
@header ||= parse_and_decode(@encoded_header)
|
|
56
|
+
@header ||= parse_and_decode(@encoded_header).tap do |decoded_header|
|
|
57
|
+
raise JWT::MalformedTokenError, 'Token header not a JSON object' unless decoded_header.is_a?(Hash)
|
|
58
|
+
end
|
|
56
59
|
end
|
|
57
60
|
|
|
58
61
|
# Returns the encoded header of the JWT token.
|
|
@@ -122,6 +125,7 @@ module JWT
|
|
|
122
125
|
# @param signature [Hash] the parameters for signature verification (see {#verify_signature!}).
|
|
123
126
|
# @param claims [Array<Symbol>, Hash] the claims to verify (see {#verify_claims!}).
|
|
124
127
|
# @return [Boolean] true if the signature and claims are valid, false otherwise.
|
|
128
|
+
# @raise [JWT::MalformedTokenError] if the token is structurally invalid.
|
|
125
129
|
def valid?(signature:, claims: nil)
|
|
126
130
|
valid_signature?(**signature) &&
|
|
127
131
|
(claims.is_a?(Array) ? valid_claims?(*claims) : valid_claims?(claims))
|
|
@@ -134,6 +138,7 @@ module JWT
|
|
|
134
138
|
# @param key_finder [#call] an object responding to `call` to find the key for verification.
|
|
135
139
|
# @return [nil]
|
|
136
140
|
# @raise [JWT::VerificationError] if the signature verification fails.
|
|
141
|
+
# @raise [JWT::MalformedTokenError] if the token is structurally invalid.
|
|
137
142
|
# @raise [ArgumentError] if neither key nor key_finder is provided, or if both are provided.
|
|
138
143
|
def verify_signature!(algorithm:, key: nil, key_finder: nil)
|
|
139
144
|
return if valid_signature?(algorithm: algorithm, key: key, key_finder: key_finder)
|
|
@@ -146,10 +151,17 @@ module JWT
|
|
|
146
151
|
# @param algorithm [String, Array<String>, Object, Array<Object>] the algorithm(s) to use for verification.
|
|
147
152
|
# @param key [String, Array<String>, JWT::JWK::KeyBase, Array<JWT::JWK::KeyBase>] the key(s) to use for verification.
|
|
148
153
|
# @param key_finder [#call] an object responding to `call` to find the key for verification.
|
|
154
|
+
# Not called if the token's algorithm is not among the given algorithms, in which case the
|
|
155
|
+
# signature is not valid. The token's alg header is not compared when a key is given directly.
|
|
149
156
|
# @return [Boolean] true if the signature is valid, false otherwise.
|
|
157
|
+
# @raise [JWT::MalformedTokenError] if the token is structurally invalid.
|
|
150
158
|
def valid_signature?(algorithm: nil, key: nil, key_finder: nil)
|
|
151
159
|
raise ArgumentError, 'Provide either key or key_finder, not both or neither' if key.nil? == key_finder.nil?
|
|
152
160
|
|
|
161
|
+
@signature_verified = false
|
|
162
|
+
validate_segment_count!
|
|
163
|
+
return false if key_finder && !algorithm_allowed?(algorithm)
|
|
164
|
+
|
|
153
165
|
keys = Array(key || key_finder.call(self))
|
|
154
166
|
verifiers = JWA.create_verifiers(algorithms: algorithm, keys: keys, preferred_algorithm: header['alg'])
|
|
155
167
|
|
|
@@ -192,6 +204,18 @@ module JWT
|
|
|
192
204
|
|
|
193
205
|
private
|
|
194
206
|
|
|
207
|
+
def validate_segment_count!
|
|
208
|
+
raise JWT::MalformedTokenError, 'Too many segments' if jwt.count('.') > 2
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# An empty list leaves the choice of algorithm to the JWKs given by the key finder.
|
|
212
|
+
# An unknown algorithm is a configuration error that the verifier reports.
|
|
213
|
+
def algorithm_allowed?(algorithms)
|
|
214
|
+
algorithms = Array(algorithms).map { |algorithm| JWA.resolve(algorithm) }
|
|
215
|
+
|
|
216
|
+
algorithms.empty? || algorithms.any? { |algorithm| algorithm == JWA::Unsupported || algorithm.valid_alg?(header['alg']) }
|
|
217
|
+
end
|
|
218
|
+
|
|
195
219
|
def claims_options(options)
|
|
196
220
|
return DEFAULT_CLAIMS if options.first.nil?
|
|
197
221
|
|
data/lib/jwt/jwk/ec.rb
CHANGED
|
@@ -160,6 +160,8 @@ module JWT
|
|
|
160
160
|
OpenSSL::PKey::EC::Group.new(curve),
|
|
161
161
|
OpenSSL::BN.new([0x04, x_octets, y_octets].pack('Ca*a*'), 2)
|
|
162
162
|
)
|
|
163
|
+
rescue OpenSSL::PKey::EC::Point::Error
|
|
164
|
+
raise JWT::JWKError, "Invalid EC point for curve #{jwk_crv}"
|
|
163
165
|
end
|
|
164
166
|
|
|
165
167
|
if ::JWT.openssl_3?
|
|
@@ -230,7 +232,7 @@ module JWT
|
|
|
230
232
|
when 'P-256' then 'prime256v1'
|
|
231
233
|
when 'P-384' then 'secp384r1'
|
|
232
234
|
when 'P-521' then 'secp521r1'
|
|
233
|
-
when 'P-256K' then 'secp256k1'
|
|
235
|
+
when 'secp256k1', 'P-256K' then 'secp256k1'
|
|
234
236
|
else raise JWT::JWKError, 'Invalid curve provided'
|
|
235
237
|
end
|
|
236
238
|
end
|
data/lib/jwt/jwk/key_base.rb
CHANGED
data/lib/jwt/jwk/set.rb
CHANGED
|
@@ -18,7 +18,7 @@ module JWT
|
|
|
18
18
|
when JWT::JWK::Set then jwks.keys.dup
|
|
19
19
|
when JWT::JWK::KeyBase then [jwks]
|
|
20
20
|
when Hash then build_supported_keys(jwks.transform_keys(&:to_sym)[:keys], options)
|
|
21
|
-
when Array then
|
|
21
|
+
when Array then build_supported_keys(jwks, options)
|
|
22
22
|
else raise ArgumentError, 'Can only create new JWKS from Hash, Array and JWK'
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -80,10 +80,6 @@ module JWT
|
|
|
80
80
|
|
|
81
81
|
private
|
|
82
82
|
|
|
83
|
-
def build_keys(keys, options)
|
|
84
|
-
[*keys].map { |key| JWT::JWK.new(key, nil, options) }
|
|
85
|
-
end
|
|
86
|
-
|
|
87
83
|
def build_supported_keys(keys, options)
|
|
88
84
|
[*keys].each_with_object([]) do |key, arr|
|
|
89
85
|
arr << JWT::JWK.new(key, nil, options)
|
data/lib/jwt/version.rb
CHANGED
data/lib/jwt/x5c_key_finder.rb
CHANGED
|
@@ -40,13 +40,19 @@ module JWT
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def parse_certificates(x5c_header_or_certificates)
|
|
43
|
+
raise JWT::MalformedTokenError, 'Invalid x5c header parameter' unless x5c_header_or_certificates.is_a?(Array) && !x5c_header_or_certificates.empty?
|
|
44
|
+
|
|
43
45
|
if x5c_header_or_certificates.all?(OpenSSL::X509::Certificate)
|
|
44
46
|
x5c_header_or_certificates
|
|
45
|
-
|
|
47
|
+
elsif x5c_header_or_certificates.all?(String)
|
|
46
48
|
x5c_header_or_certificates.map do |encoded|
|
|
47
49
|
OpenSSL::X509::Certificate.new(::JWT::Base64.url_decode(encoded))
|
|
48
50
|
end
|
|
51
|
+
else
|
|
52
|
+
raise JWT::MalformedTokenError, 'Invalid x5c header parameter'
|
|
49
53
|
end
|
|
54
|
+
rescue OpenSSL::X509::CertificateError => e
|
|
55
|
+
raise JWT::MalformedTokenError, "Invalid x5c certificate: #{e.message}"
|
|
50
56
|
end
|
|
51
57
|
end
|
|
52
58
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jwt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.3.
|
|
4
|
+
version: 3.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tim Rudat
|
|
@@ -202,7 +202,7 @@ licenses:
|
|
|
202
202
|
- MIT
|
|
203
203
|
metadata:
|
|
204
204
|
bug_tracker_uri: https://github.com/jwt/ruby-jwt/issues
|
|
205
|
-
changelog_uri: https://github.com/jwt/ruby-jwt/blob/v3.3.
|
|
205
|
+
changelog_uri: https://github.com/jwt/ruby-jwt/blob/v3.3.1/CHANGELOG.md
|
|
206
206
|
rubygems_mfa_required: 'true'
|
|
207
207
|
rdoc_options: []
|
|
208
208
|
require_paths:
|
|
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
218
218
|
- !ruby/object:Gem::Version
|
|
219
219
|
version: '0'
|
|
220
220
|
requirements: []
|
|
221
|
-
rubygems_version: 4.0.
|
|
221
|
+
rubygems_version: 4.0.20
|
|
222
222
|
specification_version: 4
|
|
223
223
|
summary: JSON Web Token implementation in Ruby
|
|
224
224
|
test_files: []
|