Fix Resolv::DNS always returning no results

This commit is contained in:
Stanko K.R.
2025-12-05 20:09:39 +01:00
parent bc16f7582e
commit cd3751f4c1
3 changed files with 9 additions and 3 deletions
+7 -2
View File
@@ -1,8 +1,13 @@
module SsrfProtection
module SSRFProtection
extend self
DNS_RESOLUTION_TIMEOUT = 2
DNS_NAMESERVERS = %w[
1.1.1.1
8.8.8.8
]
DISALLOWED_IP_RANGES = [
IPAddr.new("0.0.0.0/8") # Broadcasts
].freeze
@@ -22,7 +27,7 @@ module SsrfProtection
def resolve_dns(hostname)
ip_addresses = []
Resolv::DNS.open(timeouts: DNS_RESOLUTION_TIMEOUT) do |dns|
Resolv::DNS.open(nameserver: DNS_NAMESERVERS, timeouts: DNS_RESOLUTION_TIMEOUT) do |dns|
dns.each_address(hostname) do |ip_address|
ip_addresses << IPAddr.new(ip_address.to_s)
end
+1 -1
View File
@@ -70,7 +70,7 @@ class Webhook::Delivery < ApplicationRecord
def resolved_ip
return @resolved_ip if defined?(@resolved_ip)
@resolved_ip = SsrfProtection.resolve_public_ip(uri.host)
@resolved_ip = SSRFProtection.resolve_public_ip(uri.host)
end
def uri
+1
View File
@@ -13,6 +13,7 @@
# These inflection rules are supported but not enabled by default:
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym "SQLite"
inflect.acronym "SSRF"
inflect.singular "quotas", "quota"
inflect.plural "quota", "quotas"