pub struct NetworkAllowlist { /* private fields */ }Expand description
Network allowlist configuration for controlling HTTP access.
URLs must match an entry in the allowlist to be accessed. An empty allowlist means all URLs are blocked (secure by default).
§Examples
use bashkit::NetworkAllowlist;
// Create allowlist for specific APIs
let allowlist = NetworkAllowlist::new()
.allow("https://api.example.com") // Allow entire host
.allow("https://cdn.example.com/assets/"); // Allow path prefix
// Check URLs
assert!(allowlist.is_allowed("https://api.example.com/v1/users"));
assert!(allowlist.is_allowed("https://cdn.example.com/assets/logo.png"));
assert!(!allowlist.is_allowed("https://evil.com"));§Pattern Matching
- Scheme: Must match exactly (https vs http)
- Host: Must match exactly (no wildcards)
- Port: Must match (defaults apply: 443 for https, 80 for http)
- Path: Pattern path is treated as a prefix
Implementations§
Source§impl NetworkAllowlist
impl NetworkAllowlist
Sourcepub fn allow_all() -> Self
pub fn allow_all() -> Self
Create an allowlist that allows all URLs.
§Warning
This is dangerous and should only be used for testing or when the script is fully trusted.
Sourcepub fn allow(self, pattern: impl Into<String>) -> Self
pub fn allow(self, pattern: impl Into<String>) -> Self
Add a URL pattern to the allowlist.
§Pattern Format
Patterns can be:
- Full URLs:
https://api.example.com/v1 - Host only:
https://example.com - With port: “http://localhost:8080”
A pattern matches if the requested URL’s scheme, host, and port match, and the requested path starts with the pattern’s path (if specified).
Sourcepub fn allow_many(
self,
patterns: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn allow_many( self, patterns: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Add multiple URL patterns to the allowlist.
Sourcepub fn is_allowed(&self, url: &str) -> bool
pub fn is_allowed(&self, url: &str) -> bool
Check if a URL is allowed (convenience method).
Returns true if the URL is allowed, false otherwise.
This is equivalent to checking if check(url) returns UrlMatch::Allowed.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if network access is enabled (has any patterns or allow_all)
Trait Implementations§
Source§impl Clone for NetworkAllowlist
impl Clone for NetworkAllowlist
Source§fn clone(&self) -> NetworkAllowlist
fn clone(&self) -> NetworkAllowlist
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more