authress-sdk 2.0.57.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: 567a20d2002ab958602143104837c4a0f0baf14c9b706d2b489d3bc9c6022956
4
- data.tar.gz: a6e44e349bddb79e760a9c719d2b0f43daad7ccb4cf88b845b7f3eedd3e744d5
3
+ metadata.gz: 42f457882255642722ed5cccf62f35520814ad7c0c346f5c2ac98e6fe4dde4d1
4
+ data.tar.gz: ae4fde3b59e4109e4049306452bd600a9149e66015405556b66b5dcfbfb6392c
5
5
  SHA512:
6
- metadata.gz: 9f3940779c0256acdf0f0b572021831319ce821a8b4d4a0db565ef4f0e7cadfa977cc768e2612147201d2b24d7e3c4cbfd25c909ad21b6ef3abc8c1e8e6c5b94
7
- data.tar.gz: 5deaf632a17b1b8e838e72fd134ba2c6a58fc395efc8420035a3fb2c64bbfb05bd836733074397118bddaa41e3e0656a0ef29ffda05ad2dec175b3db8bd51faf
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)
@@ -29,7 +29,7 @@ module AuthressSdk
29
29
  end
30
30
 
31
31
  def get_issuer(unsanitizedAuthressCustomDomain, decodedAccessKey)
32
- authressCustomDomain = sanitizeUrl(@custom_domain_url).gsub(/\/+$/, '')
32
+ authressCustomDomain = sanitizeUrl(unsanitizedAuthressCustomDomain).gsub(/\/+$/, '')
33
33
  return "#{authressCustomDomain}/v1/clients/#{decodedAccessKey.clientId}"
34
34
  end
35
35
 
@@ -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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authress-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.57.0
4
+ version: 2.0.58.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Authress
@@ -230,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
230
  - !ruby/object:Gem::Version
231
231
  version: '0'
232
232
  requirements: []
233
- rubygems_version: 3.6.7
233
+ rubygems_version: 3.6.9
234
234
  specification_version: 4
235
235
  summary: The Authress SDK for Ruby provides authorization as a service with fully
236
236
  compatible REST apis.