Skip to main content

BoundaryPath

Struct BoundaryPath 

Source
pub struct BoundaryPath(/* private fields */);
Expand description

Validates a raw, caller-supplied path string before it enters the archive pipeline. Shared by exarch-python and exarch-node. A caller-supplied path string that passed the boundary checks.

This is the shared boundary check for exarch-python and exarch-node: reject overlong strings and null bytes before doing anything else with them. It intentionally does not perform traversal, symlink, or destination-boundary checks — those require a Path, a DestDir, and a SecurityConfig, and are handled later by validate_path.

The only constructor is BoundaryPath::parse, so a binding entry point that takes a BoundaryPath cannot receive an unchecked string.

§Check order

Length is checked before scanning for a null byte: .len() is an O(1) lookup, so an oversized input is rejected without ever running the O(n) null-byte scan below it — this serves the length check’s own DoS-prevention purpose.

§Null-byte detection

Uses str::contains, which short-circuits on the first null byte. This check validates the format of caller-supplied input (is this a well-formed path string?) rather than comparing one secret against another, so there is no timing side channel to defend against and short-circuiting is safe.

§Examples

use std::path::Path;

use exarch_core::BoundaryPath;

let path = BoundaryPath::parse("archive.tar.gz".to_owned())?;
assert_eq!(path.as_str(), "archive.tar.gz");
assert_eq!(AsRef::<Path>::as_ref(&path), Path::new("archive.tar.gz"));
assert!(BoundaryPath::parse("bad\0path".to_owned()).is_err());
assert!(BoundaryPath::parse("x".repeat(5000)).is_err());

Implementations§

Source§

impl BoundaryPath

Source

pub fn parse(path: String) -> Result<Self>

Checks a raw path string and keeps it as proof of the check.

§Errors

Returns crate::ArchiveError::SecurityViolation if path contains a null byte or exceeds MAX_PATH_LENGTH bytes.

Source

pub fn as_str(&self) -> &str

The checked string.

Source

pub fn into_string(self) -> String

The checked string, by value.

Trait Implementations§

Source§

impl AsRef<Path> for BoundaryPath

Source§

fn as_ref(&self) -> &Path

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for BoundaryPath

Source§

fn clone(&self) -> Self

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 BoundaryPath

Source§

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

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

impl Eq for BoundaryPath

Source§

impl PartialEq for BoundaryPath

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for BoundaryPath

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.