json-jwt 1.16.3 → 1.17.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e15d6297f3fe38127afb9686fcf44f6718b203b15988019897901dc62ebed1ca
4
- data.tar.gz: 4fa5a17b443fb0811dc1634db20b39471aca3a7475aa4181cfe2c5c2790d7f47
3
+ metadata.gz: 477700420d1f91dfa45a302ecccc12c76548a8a5f281ac709f2b406b76e2abbf
4
+ data.tar.gz: b4e2f42d9fa50ff0902e8e72a3584ebc760d18b82c857e532f390253472d96a7
5
5
  SHA512:
6
- metadata.gz: 7869a764a0700e9d016e9b3ad30952e5e34a4a2bd1b5b58b3b48887b2d7edc2836f3ec0c7ce72f3246ebda7f00cb18409e33a79953777583f347837a5445d994
7
- data.tar.gz: 033e08b8548ad17468e07ea1f21bb115552a3d54163796a252d26b3e728382dc8d7a8f906555967eedb939b683880dec4603decadae7a80800cf0cc8dc082fbf
6
+ metadata.gz: 66ce8c45f9d3c046a749e2cff596258eec0d63ee842e8033a691efe745d8cd44b4943a8a70700cd1ee8692e4417ad67b658155a1cc7ad0cd0313d142b4751489
7
+ data.tar.gz: 21e4328f6b842ab18293bd735f973131db0a7ed1f308023ef976df3c25c9a4a0d59e6481f561bfa90b7921560eff7b856cc6b6cffc0e89f68ceb26b012847a39
@@ -3,7 +3,7 @@ name: Spec
3
3
  on:
4
4
  push:
5
5
  branches:
6
- - master
6
+ - main
7
7
  pull_request:
8
8
 
9
9
  permissions:
@@ -11,21 +11,21 @@ permissions:
11
11
 
12
12
  jobs:
13
13
  spec:
14
+ runs-on: ubuntu-latest
15
+ name: Ruby ${{ matrix.ruby }}
14
16
  strategy:
15
17
  matrix:
16
- os: ['ubuntu-20.04', 'ubuntu-22.04']
17
- ruby-version: ['3.1', '3.2']
18
- include:
19
- - os: 'ubuntu-20.04'
20
- ruby-version: '3.0'
21
- runs-on: ${{ matrix.os }}
22
-
18
+ ruby:
19
+ - '3.2'
20
+ - '3.3'
21
+ - '3.4'
22
+ - '4.0'
23
23
  steps:
24
24
  - uses: actions/checkout@v3
25
25
  - name: Set up Ruby
26
26
  uses: ruby/setup-ruby@v1
27
27
  with:
28
- ruby-version: ${{ matrix.ruby-version }}
28
+ ruby-version: ${{ matrix.ruby }}
29
29
  bundler-cache: true
30
30
  - name: Run Specs
31
31
  run: bundle exec rake spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.16.3
1
+ 1.17.1
data/json-jwt.gemspec CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.require_paths = ['lib']
15
15
  gem.required_ruby_version = '>= 2.4'
16
16
  gem.add_runtime_dependency 'activesupport', '>= 4.2'
17
+ gem.add_runtime_dependency 'base64'
17
18
  gem.add_runtime_dependency 'bindata'
18
19
  gem.add_runtime_dependency 'aes_key_wrap'
19
20
  gem.add_runtime_dependency 'faraday', '~> 2.0'
@@ -2,6 +2,8 @@ module JSON
2
2
  class JWK
3
3
  class Set
4
4
  module Fetcher
5
+ class UnexpectedFormat < JWT::Exception; end
6
+
5
7
  class Cache
6
8
  def fetch(cache_key, options = {})
7
9
  yield
@@ -65,13 +67,18 @@ module JSON
65
67
  kid
66
68
  ].collect(&:to_s).join(':')
67
69
 
68
- jwks = Set.new(
69
- JSON.parse(
70
- cache.fetch(cache_key, options) do
71
- http_client.get(jwks_uri).body
72
- end
73
- )
70
+ parsed_jwks = JSON.parse(
71
+ cache.fetch(cache_key, options) do
72
+ http_client.get(jwks_uri).body
73
+ end
74
74
  )
75
+
76
+ unless parsed_jwks.is_a?(Hash) && parsed_jwks['keys'].is_a?(Array)
77
+ cache.delete(cache_key, options)
78
+ raise UnexpectedFormat
79
+ end
80
+
81
+ jwks = Set.new(parsed_jwks)
75
82
  cache.delete(cache_key, options) if jwks[kid].blank?
76
83
 
77
84
  if auto_detect
@@ -83,4 +90,4 @@ module JSON
83
90
  end
84
91
  end
85
92
  end
86
- end
93
+ end
data/lib/json/jwk/set.rb CHANGED
@@ -31,4 +31,4 @@ module JSON
31
31
  end
32
32
  end
33
33
  end
34
- end
34
+ end
data/lib/json/jws.rb CHANGED
@@ -20,6 +20,7 @@ module JSON
20
20
 
21
21
  def verify!(public_key_or_secret, algorithms = nil)
22
22
  if alg&.to_sym == :none
23
+ raise UnexpectedAlgorithm unless algorithms.blank? || Array(algorithms).include?(:none)
23
24
  raise UnexpectedAlgorithm if public_key_or_secret
24
25
  signature == '' or raise VerificationFailed
25
26
  elsif algorithms.blank? || Array(algorithms).include?(alg&.to_sym)
@@ -124,7 +125,8 @@ module JSON
124
125
  public_key_or_secret = with_jwk_support public_key_or_secret
125
126
  case
126
127
  when hmac?
127
- secure_compare sign(signature_base_string, public_key_or_secret), signature
128
+ secret = public_key_or_secret
129
+ secure_compare sign(signature_base_string, secret), signature
128
130
  when rsa?
129
131
  public_key = public_key_or_secret
130
132
  public_key.verify digest, signature, signature_base_string
data/lib/json/jwt.rb CHANGED
@@ -26,12 +26,12 @@ module JSON
26
26
  @content_type = 'application/jwt'
27
27
  self.typ = :JWT
28
28
  self.alg = :none
29
+ update claims
29
30
  unless claims.nil?
30
31
  [:exp, :nbf, :iat].each do |key|
31
- claims[key] = claims[key].to_i if claims[key]
32
+ self[key] = self[key].to_i if self[key]
32
33
  end
33
34
  end
34
- update claims
35
35
  end
36
36
 
37
37
  def sign(private_key_or_secret, algorithm = :autodetect)
@@ -109,7 +109,11 @@ module JSON
109
109
  when JWS::NUM_OF_SEGMENTS
110
110
  JWS.decode_compact_serialized jwt_string, key_or_secret, algorithms, allow_blank_payload
111
111
  when JWE::NUM_OF_SEGMENTS
112
- JWE.decode_compact_serialized jwt_string, key_or_secret, algorithms, encryption_methods
112
+ if allow_blank_payload
113
+ raise InvalidFormat.new("JWE w/ blank payload is not supported.")
114
+ else
115
+ JWE.decode_compact_serialized jwt_string, key_or_secret, algorithms, encryption_methods
116
+ end
113
117
  else
114
118
  raise InvalidFormat.new("Invalid JWT Format. JWT should include #{JWS::NUM_OF_SEGMENTS} or #{JWE::NUM_OF_SEGMENTS} segments.")
115
119
  end
@@ -138,4 +142,4 @@ require 'json/jwe'
138
142
  require 'json/jwk'
139
143
  require 'json/jwk/jwkizable'
140
144
  require 'json/jwk/set'
141
- require 'json/jwk/set/fetcher'
145
+ require 'json/jwk/set/fetcher'
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-jwt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.3
4
+ version: 1.17.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov matake
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-01-24 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -24,6 +23,20 @@ dependencies:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: '4.2'
26
+ - !ruby/object:Gem::Dependency
27
+ name: base64
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
27
40
  - !ruby/object:Gem::Dependency
28
41
  name: bindata
29
42
  requirement: !ruby/object:Gem::Requirement
@@ -182,7 +195,6 @@ homepage: https://github.com/nov/json-jwt
182
195
  licenses:
183
196
  - MIT
184
197
  metadata: {}
185
- post_install_message:
186
198
  rdoc_options: []
187
199
  require_paths:
188
200
  - lib
@@ -197,8 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
209
  - !ruby/object:Gem::Version
198
210
  version: '0'
199
211
  requirements: []
200
- rubygems_version: 3.3.26
201
- signing_key:
212
+ rubygems_version: 4.0.10
202
213
  specification_version: 4
203
214
  summary: JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and
204
215
  JSON Web Key) in Ruby