Security
provide.foundation.archive.security
¶
Archive extraction security utilities.
Provides path validation to prevent common archive extraction vulnerabilities.
Functions¶
is_safe_path
¶
Validate that a path is safe for extraction.
Prevents: - Path traversal attacks (..) - Absolute paths - Symlinks that point outside base directory
Uses modern Path.is_relative_to() for robust path containment checks, avoiding string manipulation vulnerabilities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_dir
|
Path
|
Base extraction directory |
required |
target_path
|
str
|
Path to validate |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if path is safe, False otherwise |
Examples:
>>> base = Path("/tmp/extract")
>>> is_safe_path(base, "file.txt") # Safe
True
>>> is_safe_path(base, "../etc/passwd") # Path traversal
False
>>> is_safe_path(base, "/etc/passwd") # Absolute path
False