authress-sdk 2.0.51.0 → 2.0.58.0

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: 9a6783cbfe401d1d8558d84480575b56de12bd3b5cdc3ab1f6f0e1a78f7abee8
4
- data.tar.gz: 84ef7843414edfda955570befb90928f27c8af40f941034675aa27661aea0823
3
+ metadata.gz: 42f457882255642722ed5cccf62f35520814ad7c0c346f5c2ac98e6fe4dde4d1
4
+ data.tar.gz: ae4fde3b59e4109e4049306452bd600a9149e66015405556b66b5dcfbfb6392c
5
5
  SHA512:
6
- metadata.gz: 2e614e2759efb7a312a6ad104dddf588fdfdd105745d8180cb04d4c3e39403b01247b0682d4165b0e4db2f28ea4acd8e40e95651d2373d00ffd0df5908a7aba2
7
- data.tar.gz: 89f1a2ac1e69c008902cb1f4e8979010db01fdba92b53a077f064771d31bdb75cc6a789d1b6be79992269a306318ab813331d10e7829b53954bd09d9ec8684e9
6
+ metadata.gz: b95e5a2773c2fd9c3d8d1dac280d99b43731b2228fc303163ecacfa7f2ca369985e027d656953029861e0b19589b49c801504c6722d4aafcb56b936edc377be9
7
+ data.tar.gz: 7bc10d2e16bc948b56adef2c525ceb2ea7fd637f503d95467eb523f29fc885295c780d2db0704cdc00e15d9a8170e1b800a930f0fbcb150ac06d0230afea42b1
@@ -43,7 +43,7 @@ module AuthressSdk
43
43
  def custom_domain_url
44
44
  domain_url = URI(@base_url)
45
45
  domain_url = URI("https://#{domain_url}") if domain_url.scheme.nil?
46
- domain_url.to_s
46
+ domain_url.to_s.gsub(/\/+\z/, '')
47
47
  end
48
48
 
49
49
  def set_token(token)
@@ -2,6 +2,7 @@ require 'time'
2
2
  require 'json'
3
3
  require 'logger'
4
4
  require 'uri'
5
+ require 'jwt/eddsa'
5
6
 
6
7
  module AuthressSdk
7
8
  class ServiceClientTokenProvider
@@ -28,7 +29,7 @@ module AuthressSdk
28
29
  end
29
30
 
30
31
  def get_issuer(unsanitizedAuthressCustomDomain, decodedAccessKey)
31
- authressCustomDomain = sanitizeUrl(@custom_domain_url).gsub(/\/+$/, '')
32
+ authressCustomDomain = sanitizeUrl(unsanitizedAuthressCustomDomain).gsub(/\/+$/, '')
32
33
  return "#{authressCustomDomain}/v1/clients/#{decodedAccessKey.clientId}"
33
34
  end
34
35
 
@@ -70,9 +71,9 @@ module AuthressSdk
70
71
 
71
72
  privateKey = OpenSSL::PKey.read(priv_pem)
72
73
  result = Base64.encode64(privateKey.raw_private_key).tr('+/', '-_').delete('=')
73
- private_key = RbNaCl::Signatures::Ed25519::SigningKey.new(Base64.decode64(result))
74
+ private_key = Ed25519::SigningKey.new(Base64.decode64(result))
74
75
 
75
- token = JWT.encode(jwt, private_key, 'ED25519', { typ: 'at+jwt', alg: 'EdDSA', kid: decodedAccessKey.keyId })
76
+ token = JWT.encode(jwt, private_key, 'EdDSA', { typ: 'at+jwt', alg: 'EdDSA', kid: decodedAccessKey.keyId })
76
77
  @cachedKeyData = { token: token, expires: jwt['exp'] }
77
78
  return token
78
79
  end
@@ -46,18 +46,22 @@ module AuthressSdk
46
46
  raise TokenVerificationError.new("Unauthorized: No Issuer in token")
47
47
  end
48
48
 
49
+ canonicalIssuer = get_canonical_issuer(issuer)
50
+ if canonicalIssuer.nil?
51
+ raise TokenVerificationError.new("Unauthorized: Issuer is not in canonical form")
52
+ end
53
+
49
54
  if (URI(issuer).host != URI(completeIssuerUrl).host)
50
55
  raise TokenVerificationError.new("Unauthorized: Issuer does not match")
51
56
  end
52
57
 
53
58
  # Handle service client checking
54
- issuerPath = URI(issuer).path
55
- clientIdMatcher = /^\/v\d\/clients\/([^\/]+)$/.match(issuerPath)
59
+ clientIdMatcher = /\A\/v\d\/clients\/([^\/]+)\/?\z/.match(canonicalIssuer[:path])
56
60
  if clientIdMatcher && clientIdMatcher[1] != unverifiedPayload[0]['sub']
57
61
  raise TokenVerificationError.new("Unauthorized: Service ID does not match token sub claim")
58
62
  end
59
63
 
60
- jwkObject = get_public_key("#{issuer}/.well-known/openid-configuration/jwks", kid)
64
+ jwkObject = get_public_key("#{canonicalIssuer[:url]}/.well-known/openid-configuration/jwks", kid)
61
65
  jwk = jwkObject.verify_key()
62
66
 
63
67
  begin
@@ -69,6 +73,18 @@ module AuthressSdk
69
73
  end
70
74
  end
71
75
 
76
+ # The service client check and the JWKS fetch must read the same issuer value. Any issuer that a runtime could normalise differently is rejected.
77
+ def get_canonical_issuer(issuer)
78
+ issuerMatch = issuer =~ /[?#\\]/ ? nil : /\A([a-z][a-z0-9+.-]*:\/\/[^\/@]+)(\/.*)?\z/i.match(issuer)
79
+ return nil if issuerMatch.nil?
80
+
81
+ path = (issuerMatch[2] || '').delete_suffix('/')
82
+ segments = path.empty? ? [] : path[1..].split('/', -1)
83
+ return nil if segments.any? { |segment| segment.empty? || segment == '.' || segment == '..' || segment =~ /%(2e|2f|5c)/i }
84
+
85
+ { url: "#{issuerMatch[1]}#{path}", path: path }
86
+ end
87
+
72
88
  def get_public_key(jwkKeyListUrl, kid)
73
89
  hashKey = "#{jwkKeyListUrl}|#{kid}"
74
90
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authress-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.51.0
4
+ version: 2.0.58.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Authress
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-03-11 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: typhoeus
@@ -72,6 +71,20 @@ dependencies:
72
71
  - - ">="
73
72
  - !ruby/object:Gem::Version
74
73
  version: '2.8'
74
+ - !ruby/object:Gem::Dependency
75
+ name: jwt-eddsa
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ type: :runtime
82
+ prerelease: false
83
+ version_requirements: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
75
88
  - !ruby/object:Gem::Dependency
76
89
  name: oauth2
77
90
  requirement: !ruby/object:Gem::Requirement
@@ -203,7 +216,6 @@ metadata:
203
216
  homepage_uri: https://github.com/Authress/authress-sdk.rb
204
217
  source_code_uri: https://github.com/Authress/authress-sdk.rb
205
218
  wiki_uri: https://github.com/Authress/authress-sdk.rb/wiki
206
- post_install_message:
207
219
  rdoc_options: []
208
220
  require_paths:
209
221
  - lib
@@ -218,8 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
230
  - !ruby/object:Gem::Version
219
231
  version: '0'
220
232
  requirements: []
221
- rubygems_version: 3.4.6
222
- signing_key:
233
+ rubygems_version: 3.6.9
223
234
  specification_version: 4
224
235
  summary: The Authress SDK for Ruby provides authorization as a service with fully
225
236
  compatible REST apis.