SsrfGuard class

Security guard that protects outbound HTTP requests (URL inspector, crawler preview) against Server-Side Request Forgery (SSRF), internal network scanning, and cloud metadata access.

Constructors

SsrfGuard({Set<String> allowedHosts = const {}, bool allowLocalhostInDev = false, Future<List<InternetAddress>> resolver(String host) = _systemResolver})
const

Properties

allowedHosts → Set<String>
Optional strict hostname allowlist.
final
allowLocalhostInDev → bool
Whether localhost/loopback is permitted for local development inspection. This opt-in permits loopback only; private, link-local and special-purpose ranges remain blocked.
final
hashCode → int
The hash code for this object.
no setterinherited
resolver → Future<List<InternetAddress>> Function(String host)
Resolver hook for deterministic tests and controlled server environments. Every returned address is checked; an empty or mixed unsafe result fails closed.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

createPinnedClient({Duration connectionTimeout = const Duration(seconds: 10)}) → Client
Creates an http.Client that pins every socket connection directly to an IP address that was validated against SSRF rules, preventing DNS rebinding.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resolveAndValidate(Uri uri) → Future<List<InternetAddress>>
Resolves uri and returns only after every candidate address passes policy. A pinned socket transport must connect directly to one of these returned addresses instead of resolving the hostname again.
toString() → String
A string representation of this object.
inherited
validateUri(Uri uri) → Future<void>
Validates uri against SSRF boundaries before making any network connection. Throws SecurityException if the target violates security constraints.

Operators

operator ==(Object other) → bool
The equality operator.
inherited