Class: RailsAiBridge::Registry::PinningHttpAdapter
- Inherits:
-
Faraday::Adapter::NetHttp
- Object
- Faraday::Adapter::NetHttp
- RailsAiBridge::Registry::PinningHttpAdapter
- Defined in:
- lib/rails_ai_bridge/registry/pinning_http_adapter.rb
Overview
Faraday adapter that pins a provider connection to one of the IP addresses already approved by EndpointPolicy, while preserving the original Host header and TLS SNI.
The default Faraday :net_http adapter resolves the URL hostname at connect time, which allows a DNS rebinding attack to bypass the SSRF allowlist. This adapter closes that gap by connecting directly to a policy-validated address and setting Net::HTTP#hostname to the original host so certificate validation and SNI continue to work.
Instance Method Summary collapse
-
#initialize(app = nil, addresses:, original_host:, **opts) ⇒ PinningHttpAdapter
constructor
A new instance of PinningHttpAdapter.
-
#net_http_connection(env) ⇒ Net::HTTP
Builds a Net::HTTP connection that connects to the pinned address while presenting the original hostname for SNI and the Host header.
Constructor Details
#initialize(app = nil, addresses:, original_host:, **opts) ⇒ PinningHttpAdapter
Returns a new instance of PinningHttpAdapter.
27 28 29 30 31 |
# File 'lib/rails_ai_bridge/registry/pinning_http_adapter.rb', line 27 def initialize(app = nil, addresses:, original_host:, **opts, &) @addresses = Array(addresses) @original_host = original_host super(app, opts, &) end |
Instance Method Details
#net_http_connection(env) ⇒ Net::HTTP
Builds a Net::HTTP connection that connects to the pinned address while presenting the original hostname for SNI and the Host header.
38 39 40 41 42 |
# File 'lib/rails_ai_bridge/registry/pinning_http_adapter.rb', line 38 def net_http_connection(env) super.tap do |http| http.ipaddr = @addresses.first end end |