Skip to main content

Module error

Module error 

Source
Expand description

Error types for AntiSSRF operations.

Every fallible operation in this crate returns AntiSSRFError, a single enum that covers validation failures, configuration mistakes, and runtime policy violations. The error type implements std::error::Error via thiserror, and is Clone + PartialEq so it can be cheaply passed around and compared in tests.

§Error categories

VariantTriggered byTypical cause
IPDisallowedAntiSSRFPolicy::validate_request, DNS resolution, redirectsTarget IP is in a denylist or not in the allowlist
SchemeDisallowedAntiSSRFPolicy::validate_requesthttp:// used when set_allow_plaintext_http is false
HeaderDeniedAntiSSRFPolicy::validate_requestRequest contains a header in the denylist
HeaderRequiredAntiSSRFPolicy::validate_requestRequest is missing a header in the required list
InvalidHeaderAntiSSRFPolicy configuration methodsEmpty or malformed header name supplied at build time
PolicyLockedMutating a locked AntiSSRFPolicyAttempting to modify a policy after it has been used
ConflictingConfigurationAntiSSRFPolicy configuration methodsLogically incompatible options (e.g. denylist + deny_all_unspecified_ips)
InvalidCIDRCIDRBlock::parseMalformed CIDR string such as 10.0.0.0/33
InvalidIPIP parsing helpersString that does not represent a valid IPv4 or IPv6 address
InvalidURLURL parsing helpersString that is not a valid URL
RedirectValidationFailednetwork middlewareA redirect Location failed re-validation against the active policy

§Example

use antissrf::{AntiSSRFPolicy, PolicyConfigOptions, AntiSSRFError};

let mut policy = AntiSSRFPolicy::new(PolicyConfigOptions::ExternalOnlyLatest);
policy.set_allow_plaintext_http(false)?;

let mut headers = vec![];
match policy.validate_request("http:", &mut headers) {
    Err(AntiSSRFError::SchemeDisallowed) => {
        // plaintext HTTP rejected
    }
    Err(AntiSSRFError::IPDisallowed) => {
        // IMDS address blocked
    }
    Ok(_) => {}
    Err(e) => panic!("unexpected error: {}", e),
}

Enums§

AntiSSRFError
Error types for AntiSSRF operations.