Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/ssrf_protection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module SSRFProtection
def resolve_public_ip(hostname)
ip_addresses = resolve_dns(hostname)
public_ips = ip_addresses.reject { |ip| private_address?(ip) }
public_ips.first&.to_s
public_ips.sort_by { |ipaddr| ipaddr.ipv4? ? 0 : 1 }.first&.to_s
end

def private_address?(ip)
Expand Down
3 changes: 2 additions & 1 deletion app/models/webhook/delivery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def uri
end

def http
Net::HTTP.new(uri.host, uri.port, ipaddr: resolved_ip).tap do |http|
Net::HTTP.new(uri.host, uri.port).tap do |http|
http.ipaddr = resolved_ip
http.use_ssl = (uri.scheme == "https")
http.open_timeout = ENDPOINT_TIMEOUT
http.read_timeout = ENDPOINT_TIMEOUT
Expand Down
3 changes: 2 additions & 1 deletion test/models/webhook/delivery_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,12 @@ class Webhook::DeliveryTest < ActiveSupport::TestCase
# Verify Net::HTTP.new is called with the pinned IP
http_mock = mock("http")
http_mock.stubs(:use_ssl=)
http_mock.stubs(:ipaddr=)
http_mock.stubs(:open_timeout=)
http_mock.stubs(:read_timeout=)
http_mock.stubs(:request).returns(stub(code: "200"))

Net::HTTP.expects(:new).with("example.com", 443, ipaddr: PUBLIC_TEST_IP).returns(http_mock)
Net::HTTP.expects(:new).with("example.com", 443).returns(http_mock)

delivery.deliver

Expand Down