Class: WSDL::HTTP::Client
- Inherits:
-
Object
- Object
- WSDL::HTTP::Client
- Includes:
- RedirectGuard, Log
- Defined in:
- lib/wsdl/http/client.rb
Overview
HTTP client using Ruby's stdlib net/http.
This is the default HTTP client used by WSDL. It provides a simple interface for making GET and POST requests with no external dependencies.
Security Defaults
This client 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 client 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 - IETF protocol assignments:
192.0.0.0/24 - Documentation:
192.0.2.0/24,198.51.100.0/24,203.0.113.0/24 - 6to4 relay anycast:
192.88.99.0/24 - Benchmarking:
198.18.0.0/15 - Reserved/broadcast:
240.0.0.0/4,255.255.255.255 - IPv6 unspecified:
::/128 - NAT64:
64:ff9b::/96,64:ff9b:1::/48 - Discard-only:
100::/64 - Teredo:
2001::/32 - ORCHID:
2001:10::/28 - IPv6 documentation:
2001:db8::/32 - 6to4:
2002::/16
Both IP address literals in the URL and DNS-resolved addresses are checked. HTTPS-to-HTTP scheme downgrades are also blocked.
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
Constants included from RedirectGuard
RedirectGuard::DNS_RESOLUTION_TIMEOUT, RedirectGuard::PRIVATE_IP_RANGES, RedirectGuard::SENSITIVE_HEADERS
Instance Attribute Summary collapse
-
#config ⇒ Config
readonly
Returns the Config instance for customizing timeouts, SSL, and redirects.
Instance Method Summary collapse
-
#get(url) ⇒ Response
Executes an HTTP GET request.
-
#initialize ⇒ Client
constructor
Creates a new Client instance with secure defaults.
-
#post(url, headers, body) ⇒ Response
Executes an HTTP POST request.
-
#ssl_verification_disabled? ⇒ Boolean
Checks if SSL certificate verification is currently disabled.
Methods included from Log
Constructor Details
Instance Attribute Details
#config ⇒ Config (readonly)
Returns the WSDL::HTTP::Config instance for customizing timeouts, SSL, and redirects.
127 128 129 |
# File 'lib/wsdl/http/client.rb', line 127 def config @config end |
Instance Method Details
#get(url) ⇒ Response
Executes an HTTP GET request.
133 134 135 136 |
# File 'lib/wsdl/http/client.rb', line 133 def get(url) warn_if_ssl_verification_disabled request_with_redirects(:get, URI(url)) end |
#post(url, headers, body) ⇒ Response
Executes an HTTP POST request.
144 145 146 147 |
# File 'lib/wsdl/http/client.rb', line 144 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.
152 153 154 |
# File 'lib/wsdl/http/client.rb', line 152 def ssl_verification_disabled? @config.verify_mode == OpenSSL::SSL::VERIFY_NONE end |