Class: WSDL::HTTPAdapter
- Inherits:
-
Object
- Object
- WSDL::HTTPAdapter
- Includes:
- RedirectGuard, Log
- Defined in:
- lib/wsdl/http_adapter.rb,
lib/wsdl/http_adapter/config.rb,
lib/wsdl/http_adapter/redirect_guard.rb
Overview
HTTP adapter using Ruby's stdlib +net/http+.
This is the default HTTP adapter used by WSDL. It provides a simple interface for making GET and POST requests with no external dependencies.
== Security Defaults
This adapter applies secure defaults out of the box:
- Open timeout: 30 seconds
- Write timeout: 60 seconds
- Read timeout: 120 seconds
- Redirect limit: 5 redirects maximum
- SSL verification: Enabled by default (VERIFY_PEER)
- Redirect SSRF protection: Blocks redirects to private/reserved networks
- Scheme downgrade protection: Blocks HTTPS-to-HTTP redirects
These defaults prevent indefinite hangs, redirect loops, man-in-the-middle attacks, and SSRF via open redirects. You can customize them via #config which returns a Config instance.
== Redirect Security
HTTP redirects are validated before following. The adapter blocks redirects that target private or reserved IP addresses to prevent SSRF (Server-Side Request Forgery) attacks. This protects against scenarios where a malicious WSDL endpoint redirects to internal network addresses such as cloud metadata services (+169.254.169.254+), loopback interfaces (+127.0.0.1+), or RFC 1918 private networks.
Blocked address ranges:
- Loopback: +127.0.0.0/8+, +::1+
- Private: +10.0.0.0/8+, +172.16.0.0/12+, +192.168.0.0/16+
- Link-local: +169.254.0.0/16+, +fe80::/10+
- Current network: +0.0.0.0/8+
- Shared address space: +100.64.0.0/10+
Both IP address literals in the URL and DNS-resolved addresses are checked. HTTPS-to-HTTP scheme downgrades are also blocked.
Defined Under Namespace
Modules: RedirectGuard Classes: Config
Constant Summary collapse
- REDIRECT_CODES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
HTTP redirect status codes.
[301, 302, 303, 307, 308].freeze
- REDIRECT_TO_GET_CODES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Redirect codes that change the method to GET (RFC 7231).
[301, 302, 303].freeze
- DEFAULT_OPEN_TIMEOUT =
Default open (connection) timeout in seconds.
30- DEFAULT_WRITE_TIMEOUT =
Default write (send) timeout in seconds.
60- DEFAULT_READ_TIMEOUT =
Default read (receive) timeout in seconds.
120- DEFAULT_REDIRECT_LIMIT =
Default maximum number of redirects to follow. Prevents redirect loops and excessive redirect chains.
5
Constants included from RedirectGuard
RedirectGuard::DNS_RESOLUTION_TIMEOUT, RedirectGuard::PRIVATE_IP_RANGES
Instance Attribute Summary collapse
-
#config ⇒ Config
readonly
Returns the Config instance for customizing timeouts, SSL, and redirects.
Instance Method Summary collapse
-
#cache_key ⇒ String
Returns a stable cache fingerprint for parser cache partitioning.
-
#get(url) ⇒ HTTPResponse
Executes an HTTP GET request.
-
#initialize ⇒ HTTPAdapter
constructor
Creates a new HTTPAdapter instance with secure defaults.
-
#post(url, headers, body) ⇒ HTTPResponse
Executes an HTTP POST request.
-
#ssl_verification_disabled? ⇒ Boolean
Checks if SSL certificate verification is currently disabled.
Methods included from Log
Constructor Details
#initialize ⇒ HTTPAdapter
Creates a new HTTPAdapter instance with secure defaults.
108 109 110 |
# File 'lib/wsdl/http_adapter.rb', line 108 def initialize @config = Config.new end |
Instance Attribute Details
Instance Method Details
#cache_key ⇒ String
Returns a stable cache fingerprint for parser cache partitioning.
120 121 122 |
# File 'lib/wsdl/http_adapter.rb', line 120 def cache_key self.class.name end |
#get(url) ⇒ HTTPResponse
Executes an HTTP GET request.
128 129 130 131 |
# File 'lib/wsdl/http_adapter.rb', line 128 def get(url) warn_if_ssl_verification_disabled request_with_redirects(:get, URI(url)) end |
#post(url, headers, body) ⇒ HTTPResponse
Executes an HTTP POST request.
139 140 141 142 |
# File 'lib/wsdl/http_adapter.rb', line 139 def post(url, headers, body) warn_if_ssl_verification_disabled request_with_redirects(:post, URI(url), headers, body) end |
#ssl_verification_disabled? ⇒ Boolean
Checks if SSL certificate verification is currently disabled.
147 148 149 |
# File 'lib/wsdl/http_adapter.rb', line 147 def ssl_verification_disabled? @config.verify_mode == OpenSSL::SSL::VERIFY_NONE end |