pub struct ArchivePolicy {
pub allow_absolute_paths: bool,
pub allow_parent_traversal: bool,
pub allow_symlinks: bool,
pub max_entry_size: Option<u64>,
pub max_total_size: Option<u64>,
pub max_entries: Option<usize>,
}Expand description
Policy primitives for safe extraction planning.
Fields§
§allow_absolute_paths: boolWhether absolute or root-anchored paths are allowed.
allow_parent_traversal: boolWhether parent traversal components are allowed.
allow_symlinks: boolWhether symbolic link entries are allowed.
max_entry_size: Option<u64>Maximum single entry payload size in bytes.
max_total_size: Option<u64>Maximum total known payload size in bytes.
max_entries: Option<usize>Maximum number of archive entries.
Implementations§
Source§impl ArchivePolicy
impl ArchivePolicy
Sourcepub const fn strict() -> ArchivePolicy
pub const fn strict() -> ArchivePolicy
Returns a strict extraction-oriented policy.
Examples found in repository?
6fn main() {
7 let encoding = ArchiveEncoding::from_extension("release.tar.zst");
8
9 assert_eq!(encoding.archive, ArchiveFormat::Tar);
10 assert_eq!(encoding.compression, CompressionFormat::Zstd);
11 assert!(is_safe_relative_archive_path("docs/readme.md"));
12 assert!(!is_safe_relative_archive_path("../secrets.env"));
13
14 let policy = ArchivePolicy::strict();
15 let manifest = ArchiveManifest::new(encoding).with_entries(vec![
16 ArchiveEntry::new("docs/readme.md", ArchiveEntryKind::File).with_size(128),
17 ]);
18
19 assert!(policy.allows_entries(manifest.entries()));
20 assert_eq!(manifest.file_count(), 1);
21 assert_eq!(manifest.total_size(), 128);
22}Sourcepub const fn permissive() -> ArchivePolicy
pub const fn permissive() -> ArchivePolicy
Returns a permissive policy for trusted archive metadata.
Sourcepub const fn list_only() -> ArchivePolicy
pub const fn list_only() -> ArchivePolicy
Returns a policy suitable for listing-only workflows.
Sourcepub const fn with_max_entry_size(self, max_entry_size: u64) -> ArchivePolicy
pub const fn with_max_entry_size(self, max_entry_size: u64) -> ArchivePolicy
Adds a maximum single entry size.
Sourcepub const fn with_max_total_size(self, max_total_size: u64) -> ArchivePolicy
pub const fn with_max_total_size(self, max_total_size: u64) -> ArchivePolicy
Adds a maximum total known size.
Sourcepub const fn with_max_entries(self, max_entries: usize) -> ArchivePolicy
pub const fn with_max_entries(self, max_entries: usize) -> ArchivePolicy
Adds a maximum entry count.
Sourcepub fn allows_path(&self, path: &str) -> bool
pub fn allows_path(&self, path: &str) -> bool
Returns whether a path is allowed by this policy.
Sourcepub fn entry_issues(&self, entry: &ArchiveEntry) -> Vec<ArchivePolicyIssue>
pub fn entry_issues(&self, entry: &ArchiveEntry) -> Vec<ArchivePolicyIssue>
Returns policy issues for a single entry.
Sourcepub fn allows_entry(&self, entry: &ArchiveEntry) -> bool
pub fn allows_entry(&self, entry: &ArchiveEntry) -> bool
Returns whether a single entry is allowed by this policy.
Sourcepub fn entries_issues(
&self,
entries: &[ArchiveEntry],
) -> Vec<ArchivePolicyIssue>
pub fn entries_issues( &self, entries: &[ArchiveEntry], ) -> Vec<ArchivePolicyIssue>
Returns policy issues for a complete entry listing.
Sourcepub fn allows_entries(&self, entries: &[ArchiveEntry]) -> bool
pub fn allows_entries(&self, entries: &[ArchiveEntry]) -> bool
Returns whether a complete entry listing is allowed by this policy.
Examples found in repository?
6fn main() {
7 let encoding = ArchiveEncoding::from_extension("release.tar.zst");
8
9 assert_eq!(encoding.archive, ArchiveFormat::Tar);
10 assert_eq!(encoding.compression, CompressionFormat::Zstd);
11 assert!(is_safe_relative_archive_path("docs/readme.md"));
12 assert!(!is_safe_relative_archive_path("../secrets.env"));
13
14 let policy = ArchivePolicy::strict();
15 let manifest = ArchiveManifest::new(encoding).with_entries(vec![
16 ArchiveEntry::new("docs/readme.md", ArchiveEntryKind::File).with_size(128),
17 ]);
18
19 assert!(policy.allows_entries(manifest.entries()));
20 assert_eq!(manifest.file_count(), 1);
21 assert_eq!(manifest.total_size(), 128);
22}Trait Implementations§
Source§impl Clone for ArchivePolicy
impl Clone for ArchivePolicy
Source§fn clone(&self) -> ArchivePolicy
fn clone(&self) -> ArchivePolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ArchivePolicy
impl Debug for ArchivePolicy
Source§impl Default for ArchivePolicy
impl Default for ArchivePolicy
Source§fn default() -> ArchivePolicy
fn default() -> ArchivePolicy
Source§impl Hash for ArchivePolicy
impl Hash for ArchivePolicy
Source§impl Ord for ArchivePolicy
impl Ord for ArchivePolicy
Source§fn cmp(&self, other: &ArchivePolicy) -> Ordering
fn cmp(&self, other: &ArchivePolicy) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for ArchivePolicy
impl PartialEq for ArchivePolicy
Source§fn eq(&self, other: &ArchivePolicy) -> bool
fn eq(&self, other: &ArchivePolicy) -> bool
self and other values to be equal, and is used by ==.