pub struct UrlValidator { /* private fields */ }Expand description
URL validator with SSRF protection.
Validates URLs before fetching to prevent Server-Side Request Forgery attacks. By default, blocks access to:
- Localhost and loopback addresses
- Private IP ranges (10.x, 172.16-31.x, 192.168.x)
- Cloud metadata endpoints (AWS, GCP)
§Example
ⓘ
use agent_sdk::web::UrlValidator;
let validator = UrlValidator::new();
assert!(validator.validate("https://example.com").is_ok());
assert!(validator.validate("http://localhost").is_err());Implementations§
Source§impl UrlValidator
impl UrlValidator
Sourcepub fn with_allowed_domains(self, domains: Vec<String>) -> Self
pub fn with_allowed_domains(self, domains: Vec<String>) -> Self
Only allow URLs from specific domains.
Sourcepub fn with_blocked_hosts(self, hosts: Vec<String>) -> Self
pub fn with_blocked_hosts(self, hosts: Vec<String>) -> Self
Add additional blocked hosts.
Sourcepub const fn with_allow_private_ips(self, allow: bool) -> Self
pub const fn with_allow_private_ips(self, allow: bool) -> Self
Allow private IP ranges (dangerous - use with caution).
Sourcepub const fn with_max_redirects(self, max: usize) -> Self
pub const fn with_max_redirects(self, max: usize) -> Self
Set maximum redirects.
Sourcepub const fn with_allow_http(self) -> Self
pub const fn with_allow_http(self) -> Self
Allow HTTP URLs (default requires HTTPS).
Sourcepub const fn max_redirects(&self) -> usize
pub const fn max_redirects(&self) -> usize
Get the maximum number of redirects allowed.
Trait Implementations§
Source§impl Clone for UrlValidator
impl Clone for UrlValidator
Source§fn clone(&self) -> UrlValidator
fn clone(&self) -> UrlValidator
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UrlValidator
impl Debug for UrlValidator
Auto Trait Implementations§
impl Freeze for UrlValidator
impl RefUnwindSafe for UrlValidator
impl Send for UrlValidator
impl Sync for UrlValidator
impl Unpin for UrlValidator
impl UnwindSafe for UrlValidator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more