pub struct HardlinkTracker { /* private fields */ }Expand description
Tracks hardlink targets during extraction.
Hardlinks in archives can be used for attacks:
- Link to files outside the extraction directory
- Create multiple hardlinks to the same file (resource exhaustion)
- Link to sensitive files (if absolute paths allowed)
This tracker ensures:
- Hardlinks are allowed in the security configuration
- Targets are relative paths
- Targets resolve within the destination directory
- Duplicate hardlinks are detected
§Two-Pass Validation
Hardlinks require two-pass validation:
- First pass (during validation): Track target paths, verify they’re within bounds
- Second pass (after extraction): Verify targets actually exist
This is necessary because hardlink targets may appear later in the archive.
§Examples
use exarch_core::SecurityConfig;
use exarch_core::security::HardlinkTracker;
use exarch_core::types::DestDir;
use exarch_core::types::SafePath;
use std::path::Path;
use std::path::PathBuf;
let dest = DestDir::new(PathBuf::from("/tmp"))?;
let mut config = SecurityConfig::default();
config.allowed.hardlinks = true;
let mut tracker = HardlinkTracker::new();
let link = SafePath::validate(&PathBuf::from("link"), &dest, &config)?;
let target = Path::new("target.txt");
tracker.validate_hardlink(&link, target, &dest, &config)?;Implementations§
Source§impl HardlinkTracker
impl HardlinkTracker
Sourcepub fn validate_hardlink(
&mut self,
link_path: &SafePath,
target: &Path,
dest: &DestDir,
config: &SecurityConfig,
) -> Result<()>
pub fn validate_hardlink( &mut self, link_path: &SafePath, target: &Path, dest: &DestDir, config: &SecurityConfig, ) -> Result<()>
Validates that a hardlink target is safe and tracks it.
§Performance
Typical execution time: ~1-5 μs (HashMap insert + path validation)
§Errors
Returns an error if:
- Hardlinks are not allowed in configuration
- Target is an absolute path
- Target would escape the destination directory
§Examples
use exarch_core::SecurityConfig;
use exarch_core::security::HardlinkTracker;
use exarch_core::types::DestDir;
use exarch_core::types::SafePath;
use std::path::Path;
use std::path::PathBuf;
let dest = DestDir::new(PathBuf::from("/tmp"))?;
let mut config = SecurityConfig::default();
config.allowed.hardlinks = true;
let mut tracker = HardlinkTracker::new();
let link = SafePath::validate(&PathBuf::from("link"), &dest, &config)?;
let target = Path::new("target.txt");
tracker.validate_hardlink(&link, target, &dest, &config)?;Sourcepub fn has_target(&self, target: &Path) -> bool
pub fn has_target(&self, target: &Path) -> bool
Checks if a target path has been seen before.
Trait Implementations§
Source§impl Debug for HardlinkTracker
impl Debug for HardlinkTracker
Source§impl Default for HardlinkTracker
impl Default for HardlinkTracker
Source§fn default() -> HardlinkTracker
fn default() -> HardlinkTracker
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for HardlinkTracker
impl RefUnwindSafe for HardlinkTracker
impl Send for HardlinkTracker
impl Sync for HardlinkTracker
impl Unpin for HardlinkTracker
impl UnwindSafe for HardlinkTracker
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