Skip to main content

NetworkAllowlist

Struct NetworkAllowlist 

Source
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

Source

pub fn new() -> Self

Create a new empty allowlist (blocks all URLs)

Source

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.

Source

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).

Source

pub fn allow_many( self, patterns: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Add multiple URL patterns to the allowlist.

Source

pub fn check(&self, url: &str) -> UrlMatch

Check if a URL is allowed.

Source

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.

Source

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

Source§

fn clone(&self) -> NetworkAllowlist

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for NetworkAllowlist

Source§

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

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

impl Default for NetworkAllowlist

Source§

fn default() -> NetworkAllowlist

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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.