oauth 1.1.7 → 1.1.9

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.
@@ -1,31 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "anonymous_loader"
4
+
3
5
  module OAuth
4
6
  AUTH_SANITIZER = begin
5
- auth_sanitizer_requirement = Gem::Requirement.new("~> 0.1", ">= 0.1.3")
6
- auth_sanitizer_spec = Gem.loaded_specs["auth-sanitizer"]
7
- unless auth_sanitizer_spec && auth_sanitizer_requirement.satisfied_by?(auth_sanitizer_spec.version)
8
- # :nocov:
9
- auth_sanitizer_spec = Gem::Specification.find_by_name("auth-sanitizer", auth_sanitizer_requirement)
10
- # :nocov:
11
- end
12
-
13
- auth_sanitizer_loader_path = File.join(
14
- auth_sanitizer_spec.full_gem_path,
15
- "lib/auth_sanitizer/loader.rb",
16
- )
17
- unless File.file?(auth_sanitizer_loader_path)
18
- # :nocov:
19
- raise LoadError, "oauth requires auth-sanitizer #{auth_sanitizer_requirement}; " \
20
- "loader not found at #{auth_sanitizer_loader_path}"
21
- # :nocov:
22
- end
23
-
24
- auth_sanitizer_loader_namespace = Module.new
25
- auth_sanitizer_loader_namespace.module_eval(
26
- File.read(auth_sanitizer_loader_path),
27
- auth_sanitizer_loader_path,
28
- 1,
7
+ auth_sanitizer_requirement = Gem::Requirement.new("~> 0.2", ">= 0.2.2")
8
+ auth_sanitizer_loader_namespace = AnonymousLoader.load_path(
9
+ gem_name: "auth-sanitizer",
10
+ require_path: "auth_sanitizer/loader.rb",
11
+ version_requirement: auth_sanitizer_requirement,
12
+ version_file: "auth/sanitizer/version.rb"
29
13
  )
30
14
 
31
15
  auth_sanitizer_loader_namespace
@@ -14,7 +14,7 @@ module ActionController
14
14
  if defined? ActionDispatch
15
15
  def process_with_new_base_test(request, response = nil)
16
16
  request.apply_oauth! if request.respond_to?(:apply_oauth!)
17
- super(request, response)
17
+ super
18
18
  end
19
19
  else
20
20
  def process_with_oauth(request, response = nil)
@@ -45,7 +45,7 @@ module ActionController
45
45
  scheme: "header",
46
46
  signature_method: nil,
47
47
  nonce: nil,
48
- timestamp: nil,
48
+ timestamp: nil
49
49
  }.merge(options)
50
50
  end
51
51
 
@@ -54,7 +54,7 @@ module ActionController
54
54
 
55
55
  @oauth_helper = OAuth::Client::Helper.new(
56
56
  self,
57
- @oauth_options.merge(request_uri: (respond_to?(:fullpath) ? fullpath : request_uri)),
57
+ @oauth_options.merge(request_uri: (respond_to?(:fullpath) ? fullpath : request_uri))
58
58
  )
59
59
  @oauth_helper.amend_user_agent_header(env)
60
60
 
@@ -34,7 +34,7 @@ if OAuth::Optional.em_http_available?
34
34
  scheme: "header",
35
35
  signature_method: nil,
36
36
  nonce: nil,
37
- timestamp: nil,
37
+ timestamp: nil
38
38
  }.merge(options)
39
39
 
40
40
  @oauth_helper = OAuth::Client::Helper.new(self, options)
@@ -62,7 +62,7 @@ if OAuth::Optional.em_http_available?
62
62
  scheme: "header",
63
63
  signature_method: nil,
64
64
  nonce: nil,
65
- timestamp: nil,
65
+ timestamp: nil
66
66
  }.merge(options)
67
67
 
68
68
  OAuth::Client::Helper.new(self, options).signature_base_string
@@ -38,7 +38,7 @@ module OAuth
38
38
  "oauth_nonce" => nonce,
39
39
  "oauth_verifier" => options[:oauth_verifier],
40
40
  "oauth_version" => options[:oauth_version] || "1.0",
41
- "oauth_session_handle" => options[:oauth_session_handle],
41
+ "oauth_session_handle" => options[:oauth_session_handle]
42
42
  }
43
43
  allowed_empty_params = options[:allow_empty_params]
44
44
  if allowed_empty_params != true && !allowed_empty_params.is_a?(Array)
@@ -53,7 +53,7 @@ module OAuth
53
53
  uri: options[:request_uri],
54
54
  consumer: options[:consumer],
55
55
  token: options[:token],
56
- unsigned_parameters: options[:unsigned_parameters],
56
+ unsigned_parameters: options[:unsigned_parameters]
57
57
  }.merge(extra_options))
58
58
  end
59
59
 
@@ -62,7 +62,7 @@ module OAuth
62
62
  uri: options[:request_uri],
63
63
  consumer: options[:consumer],
64
64
  token: options[:token],
65
- parameters: oauth_parameters,
65
+ parameters: oauth_parameters
66
66
  }.merge(extra_options))
67
67
  end
68
68
 
@@ -66,7 +66,7 @@ module Net
66
66
  signature_method: nil,
67
67
  nonce: nil,
68
68
  timestamp: nil,
69
- body_hash_enabled: true,
69
+ body_hash_enabled: true
70
70
  }.merge(options)
71
71
  end
72
72
 
@@ -95,7 +95,15 @@ module OAuth
95
95
  # attacker-controlled endpoint, so they require explicit opt-in.
96
96
  token_request_max_redirects: 10,
97
97
  token_request_cross_origin_redirects: false,
98
- },
98
+
99
+ # AccessToken service calls (AccessToken#get/#post/...) may target an
100
+ # absolute URI. By default such a call is permitted only when it shares
101
+ # the configured site's origin (scheme, host, and port); a cross-origin
102
+ # absolute URI raises OAuth::Error, since it would send the signed OAuth
103
+ # Authorization header to a different host (credential leak / SSRF). Set
104
+ # this to true to allow calling service endpoints on other origins.
105
+ access_token_cross_origin_requests: false
106
+ }
99
107
  )
100
108
 
101
109
  attr_accessor :options, :key, :secret
@@ -142,6 +150,7 @@ module OAuth
142
150
  def debug_output
143
151
  @debug_output ||= case @options[:debug_output]
144
152
  when nil, false
153
+ nil
145
154
  when true
146
155
  $stdout
147
156
  else
@@ -241,7 +250,7 @@ module OAuth
241
250
  (request_token_url? ? request_token_url : request_token_path),
242
251
  nil,
243
252
  request_options,
244
- *arguments,
253
+ *arguments
245
254
  )
246
255
  end
247
256
  OAuth::RequestToken.from_hash(self, response)
@@ -372,12 +381,25 @@ module OAuth
372
381
  end
373
382
 
374
383
  def token_request_cross_origin?(current_uri, redirected_uri)
375
- current_uri.scheme.to_s.downcase != redirected_uri.scheme.to_s.downcase ||
376
- current_uri.host.to_s.downcase != redirected_uri.host.to_s.downcase ||
377
- token_request_effective_port(current_uri) != token_request_effective_port(redirected_uri)
384
+ cross_origin?(current_uri, redirected_uri)
385
+ end
386
+
387
+ # Whether the consumer permits AccessToken service calls to an absolute URI
388
+ # whose origin differs from the configured site. Off by default.
389
+ def access_token_cross_origin_requests?
390
+ !!options[:access_token_cross_origin_requests]
391
+ end
392
+
393
+ # True when the two URIs differ in scheme, host, or effective port. Used
394
+ # both for token-request redirect safety and for AccessToken service-call
395
+ # origin checks.
396
+ def cross_origin?(uri_a, uri_b)
397
+ uri_a.scheme.to_s.downcase != uri_b.scheme.to_s.downcase ||
398
+ uri_a.host.to_s.downcase != uri_b.host.to_s.downcase ||
399
+ effective_port(uri_a) != effective_port(uri_b)
378
400
  end
379
401
 
380
- def token_request_effective_port(uri)
402
+ def effective_port(uri)
381
403
  return uri.port if uri.port
382
404
  return 443 if uri.scheme == "https"
383
405
 
@@ -490,7 +512,7 @@ module OAuth
490
512
  proxy_uri.host,
491
513
  proxy_uri.port,
492
514
  proxy_uri.user,
493
- proxy_uri.password,
515
+ proxy_uri.password
494
516
  )
495
517
  end
496
518
 
@@ -32,7 +32,7 @@ module OAuth
32
32
 
33
33
  def normalized_uri
34
34
  super
35
- rescue StandardError
35
+ rescue
36
36
  # if this is a non-standard URI, it may not parse properly
37
37
  # in that case, assume that it's already been normalized
38
38
  uri
data/lib/oauth/server.rb CHANGED
@@ -13,7 +13,7 @@ module OAuth
13
13
  @@server_paths = {
14
14
  request_token_path: "/oauth/request_token",
15
15
  authorize_path: "/oauth/authorize",
16
- access_token_path: "/oauth/access_token",
16
+ access_token_path: "/oauth/access_token"
17
17
  }
18
18
 
19
19
  # Create a new server instance
@@ -40,8 +40,8 @@ module OAuth
40
40
  site: base_url,
41
41
  request_token_path: request_token_path,
42
42
  authorize_path: authorize_path,
43
- access_token_path: access_token_path,
44
- },
43
+ access_token_path: access_token_path
44
+ }
45
45
  )
46
46
  end
47
47
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "oauth/errors"
4
+
3
5
  module OAuth
4
6
  # The Access Token is used for the actual "real" web service calls that you perform against the server
5
7
  class AccessToken < ConsumerToken
@@ -9,9 +11,17 @@ module OAuth
9
11
  request_uri = URI.parse(path)
10
12
  site_uri = consumer.uri
11
13
  is_service_uri_different = request_uri.absolute? && request_uri != site_uri
14
+ if is_service_uri_different && consumer.cross_origin?(site_uri, request_uri) &&
15
+ !consumer.access_token_cross_origin_requests?
16
+ raise OAuth::Error,
17
+ "AccessToken request to cross-origin URI #{authority(request_uri)} is not permitted " \
18
+ "(configured site origin is #{authority(site_uri)}). Sending the signed OAuth Authorization " \
19
+ "header to a different origin can leak it or enable SSRF. Set the consumer option " \
20
+ "access_token_cross_origin_requests: true to allow service calls to other origins."
21
+ end
12
22
  begin
13
23
  consumer.uri(request_uri) if is_service_uri_different
14
- @response = super(http_method, path, *arguments)
24
+ @response = super
15
25
  ensure
16
26
  # NOTE: reset for wholesomeness? meaning that we admit only AccessToken service calls may use different URIs?
17
27
  # so reset in case consumer is still used for other token-management tasks subsequently?
@@ -81,5 +91,13 @@ module OAuth
81
91
  def delete(path, headers = {})
82
92
  request(:delete, path, headers)
83
93
  end
94
+
95
+ private
96
+
97
+ # scheme://host[:port] for an error message; URI::HTTP/HTTPS always
98
+ # resolve a port, so it renders whenever one is known.
99
+ def authority(uri)
100
+ "#{uri.scheme}://#{uri.host}#{":#{uri.port}" if uri.port}"
101
+ end
84
102
  end
85
103
  end
@@ -30,7 +30,7 @@ module OAuth
30
30
  (consumer.access_token_url? ? consumer.access_token_url : consumer.access_token_path),
31
31
  self,
32
32
  options,
33
- *arguments,
33
+ *arguments
34
34
  )
35
35
  OAuth::AccessToken.from_hash(consumer, response)
36
36
  end
data/lib/oauth/version.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OAuth
4
+ # Version namespace for this gem.
4
5
  module Version
5
- VERSION = "1.1.7"
6
+ # Current gem version.
7
+ VERSION = "1.1.9"
6
8
  end
9
+ # Current gem version exposed at the traditional constant location.
7
10
  VERSION = Version::VERSION # Traditional Constant Location
8
11
  end
data/lib/oauth.rb CHANGED
@@ -3,9 +3,7 @@
3
3
  # third party gems
4
4
  require "snaky_hash"
5
5
  require "version_gem"
6
- require_relative "oauth/version"
7
6
 
8
- require "oauth/version"
9
7
  require "oauth/auth_sanitizer"
10
8
 
11
9
  require "oauth/oauth"
@@ -16,6 +14,7 @@ require "oauth/signature/hmac/sha1"
16
14
  require "oauth/signature/hmac/sha256"
17
15
  require "oauth/signature/rsa/sha1"
18
16
  require "oauth/request_proxy/mock_request"
17
+ require_relative "oauth/version"
19
18
 
20
19
  OAuth::Version.class_eval do
21
20
  extend VersionGem::Basic
data/sig/oauth.rbs ADDED
@@ -0,0 +1,32 @@
1
+ module OAuth
2
+ class Consumer
3
+ include OAuth::AUTH_SANITIZER::FilteredAttributes
4
+
5
+ attr_accessor options: untyped
6
+ attr_accessor key: untyped
7
+ attr_accessor secret: untyped
8
+ end
9
+
10
+ module Signature
11
+ class Base
12
+ include OAuth::AUTH_SANITIZER::FilteredAttributes
13
+
14
+ attr_accessor options: untyped
15
+ attr_reader token_secret: untyped
16
+ attr_reader consumer_secret: untyped
17
+ attr_reader request: untyped
18
+ end
19
+ end
20
+
21
+ class Token
22
+ include OAuth::AUTH_SANITIZER::FilteredAttributes
23
+
24
+ attr_accessor token: untyped
25
+ attr_accessor secret: untyped
26
+ end
27
+
28
+ module Version
29
+ VERSION: String
30
+ end
31
+ VERSION: String
32
+ end
data.tar.gz.sig CHANGED
Binary file