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
impl BoundaryPath
Sourcepub fn parse(path: String) -> Result<Self>
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.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
The checked string, by value.
Trait Implementations§
Source§impl AsRef<Path> for BoundaryPath
impl AsRef<Path> for BoundaryPath
Source§impl Clone for BoundaryPath
impl Clone for BoundaryPath
Source§impl Debug for BoundaryPath
impl Debug for BoundaryPath
impl Eq for BoundaryPath
Source§impl PartialEq for BoundaryPath
impl PartialEq for BoundaryPath
impl StructuralPartialEq for BoundaryPath
Auto Trait Implementations§
impl Freeze for BoundaryPath
impl RefUnwindSafe for BoundaryPath
impl Send for BoundaryPath
impl Sync for BoundaryPath
impl Unpin for BoundaryPath
impl UnsafeUnpin for BoundaryPath
impl UnwindSafe for BoundaryPath
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.