Block SSRF via backchannel_logout_uri
backchannel_logout_uri was validated only for scheme/HTTPS, so an admin (or a compromised admin account) could point it at internal infrastructure — cloud metadata (169.254.169.254), loopback, or RFC1918 hosts — and every user logout would fire a server-side POST there. Add PrivateAddressCheck (app/lib) and apply it as defense-in-depth: - Application validation rejects URIs whose host is, or is a literal, internal address (loopback / private / link-local / 0.0.0.0 / localhost / metadata hostnames). Fast, DNS-free, immediate admin feedback. - BackchannelLogoutJob re-checks at request time WITH DNS resolution and aborts (no retry) if the host resolves to a non-public address — covering URIs that predate the validation and public hostnames pointed at internal IPs. Tests cover the address classification, the model validation, and updates an existing test that used a localhost logout URI. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -56,6 +56,7 @@ class Application < ApplicationRecord
|
||||
message: "must be a valid HTTP or HTTPS URL"
|
||||
}
|
||||
validate :backchannel_logout_uri_must_be_https_in_production, if: -> { backchannel_logout_uri.present? }
|
||||
validate :backchannel_logout_uri_not_internal, if: -> { backchannel_logout_uri.present? }
|
||||
|
||||
# Icon validation using ActiveStorage validators
|
||||
validate :icon_validation
|
||||
@@ -390,4 +391,17 @@ class Application < ApplicationRecord
|
||||
# Let the format validator handle invalid URIs
|
||||
end
|
||||
end
|
||||
|
||||
# SSRF guard: the backchannel logout URI is dialled server-side on every user
|
||||
# logout, so it must not target internal infrastructure (loopback, private
|
||||
# ranges, or the link-local cloud metadata endpoint). This is the fast,
|
||||
# config-time check; BackchannelLogoutJob re-checks with DNS resolution.
|
||||
def backchannel_logout_uri_not_internal
|
||||
uri = URI.parse(backchannel_logout_uri)
|
||||
if uri.host.present? && PrivateAddressCheck.internal_host?(uri.host)
|
||||
errors.add(:backchannel_logout_uri, "must not point to a private, loopback, or link-local address")
|
||||
end
|
||||
rescue URI::InvalidURIError
|
||||
# Let the format validator handle invalid URIs
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user