Skip to main content

SsrfPolicy

Struct SsrfPolicy 

Source
pub struct SsrfPolicy {
    pub reject_ip_literals: bool,
    pub allow_http: bool,
    pub allow_loopback_resolved: bool,
}
Expand description

SSRF policy applied to outbound HTTP requests.

Fields§

§reject_ip_literals: bool

If true, reject IP literals in the URL (forces DNS resolution).

§allow_http: bool

If false, only https:// URLs are accepted. Default false.

§allow_loopback_resolved: bool

When true, permit IPv4 127.0.0.0/8 and IPv6 ::1 (loopback) across Self::check_ip / Self::check_resolved_ip / [Self::pin_resolved_ip]. All other forbidden ranges (RFC 1918, link-local / IMDS, ULA, CGNAT, multicast, …) still apply. Default false.

Intended for test harnesses that resolve did:web:localhost… against a self-signed in-process HTTPS server bound to 127.0.0.1. Production callers MUST keep this false — opening loopback turns the resolver into an SSRF vector against process-internal listeners (RFC-ACDP-0008 §4.8).

Implementations§

Source§

impl SsrfPolicy

Source

pub fn check_url(&self, url: &str) -> Result<(), AcdpError>

Validate a URL string (scheme + host) before issuing a request.

Back-compat wrapper over Self::classify_url: a rejection maps to AcdpError::SchemaViolation with the same detail message callers have always seen.

Source

pub fn classify_url(&self, url: &str) -> Result<(), SsrfRejection>

Validate a URL string, returning a stable SsrfRejection (reason code + detail) on failure.

Checks scheme (HTTPS-only unless allow_http), IP-literal rejection, per-IP range filtering for literal hosts, and hostname length. Prefer this over Self::check_url when the caller needs to branch on why the URL was rejected (e.g. a language binding mapping to a typed exception).

Source

pub fn check_resolved_ip(&self, ip: IpAddr) -> Result<(), AcdpError>

Validate an already-resolved IpAddr — useful when DNS resolution is performed externally and the caller wants to filter pre-connect. Respects Self::allow_loopback_resolved.

Source

pub fn check_ip(&self, ip: IpAddr) -> Result<(), AcdpError>

Range filter for a single IpAddr, respecting the policy’s Self::allow_loopback_resolved flag.

Back-compat wrapper over Self::classify_ip.

Source

pub fn classify_ip(&self, ip: IpAddr) -> Result<(), SsrfRejection>

Range filter for a single IpAddr, returning a stable SsrfRejection (reason code + detail) when the address falls in a forbidden range. Respects Self::allow_loopback_resolved.

Source

pub fn check_redirect_authority( &self, original_url: &Url, redirect_url: &str, ) -> Result<(), AcdpError>

Per §7.5: a redirect is permitted only if it stays within the same fetch authority as the originating request — identical scheme, host, and effective port (RFC-ACDP-0008 §4.8: “host + port”).

Source

pub fn classify_redirect_authority( &self, original_url: &Url, redirect_url: &str, ) -> Result<(), SsrfRejection>

Same-authority redirect check returning a stable SsrfRejection. See Self::check_redirect_authority.

Source

pub fn classify_redirect( &self, from_url: &str, to_url: &str, ) -> Result<(), SsrfRejection>

String-in/string-in convenience over Self::classify_redirect_authority for FFI callers that hold both endpoints as strings (no url::Url on the boundary). Parses from_url as the origin authority, then applies the same scheme + host + effective-port equality.

Trait Implementations§

Source§

impl Clone for SsrfPolicy

Source§

fn clone(&self) -> SsrfPolicy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SsrfPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SsrfPolicy

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.