#[non_exhaustive]pub struct SecurityConfig {Show 15 fields
pub max_file_size: Limit<NonZeroU64>,
pub max_total_size: Limit<NonZeroU64>,
pub max_compression_ratio: RatioLimit,
pub max_file_count: Limit<NonZeroUsize>,
pub max_path_depth: NonZeroUsize,
pub allowed: AllowedFeatures,
pub preserve_permissions: bool,
pub allowed_extensions: Vec<Extension>,
pub banned_path_components: Vec<PathComponentName>,
pub solid_archives: SolidArchives,
pub max_tar_metadata_bytes: NonZeroU64,
pub max_decoder_memory: NonZeroU64,
pub compressed_member_allowance: NonZeroU64,
pub parallel_decode: ParallelDecode,
pub zip_consistency: ZipConsistencyPolicy,
}Expand description
Security configuration with default-deny settings.
This configuration controls various security checks performed during archive extraction to prevent common vulnerabilities.
§Performance Note
This struct contains heap-allocated collections
(Vec<Extension>/Vec<PathComponentName>). For performance, pass by
reference (&SecurityConfig) rather than cloning. If shared ownership is
needed across threads, consider wrapping in Arc<SecurityConfig>.
§Examples
use exarch_core::SecurityConfig;
// Use secure defaults
let config = SecurityConfig::default();
// Customize via fluent builder
let custom = SecurityConfig::default()
.with_max_file_size(exarch_core::non_zero!(100 * 1024 * 1024))
.with_max_total_size(exarch_core::non_zero!(1024 * 1024 * 1024))
.with_allow_symlinks(true);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.max_file_size: Limit<NonZeroU64>Maximum size for a single file in bytes.
max_total_size: Limit<NonZeroU64>Maximum total size for all extracted files in bytes.
max_compression_ratio: RatioLimitMaximum compression ratio allowed (uncompressed / compressed).
max_file_count: Limit<NonZeroUsize>Maximum number of entries that can be extracted.
The extraction API counts files, symlinks and hardlinks, not
directories. list and verify, and the CLI’s extract (which lists
the archive first), count every entry.
max_path_depth: NonZeroUsizeMaximum path depth allowed.
allowed: AllowedFeaturesFeature flags controlling what archive features are allowed.
Use this to enable symlinks, hardlinks, absolute paths, etc.
preserve_permissions: boolPreserve file permissions from archive.
allowed_extensions: Vec<Extension>List of allowed file extensions (empty = allow all).
Extensions are matched case-insensitively (e.g., txt matches both
file.txt and file.TXT); Extension normalizes a leading dot away.
When this list is non-empty, files without a file extension are treated as not allowed and will be skipped during extraction.
banned_path_components: Vec<PathComponentName>List of banned path components (e.g., “.git”, “.ssh”).
solid_archives: SolidArchivesWhether solid 7z archives are extracted, and under which limits.
Solid archives compress multiple files together as a single block. While this provides better compression ratios, it has security implications:
- Denial of service: a malicious archive can declare very large solid blocks that exhaust CPU time and disk space
- Decoded volume: the block limit bounds the decoded size of the
archive’s files, not resident memory; decoding streams, and the memory
of parallel decoding is bounded by
parallel_decode
Security Recommendation: Only enable for trusted archives.
Default: SolidArchives::Refuse (solid archives rejected). The limits
of an admitted policy default to SolidLimits::DEFAULT (512 MiB,
ratio 1000).
max_tar_metadata_bytes: NonZeroU64Maximum bytes the TAR reader may consume for headers and metadata records in the gap between two consecutive entries.
TAR Metadata Buffering Model:
GNU long-name (L), GNU long-link (K), and PAX extended header
(x/g) records are buffered fully into memory by the underlying
tar crate before any entry reaches the entry validator or quota
tracker — a crafted record can declare a multi-gigabyte length backed
by a tiny compressed stream, exhausting memory with no quota
enforcement (metadata-entry decompression bomb).
Enforcement Strategy:
- A read-budget wrapper meters bytes the
tarcrate reads while searching for the next entry (headers, long-name/long-link/PAX records, GNU sparse extension blocks) and returns an error oncemax_tar_metadata_bytesis exceeded, before any oversized allocation completes - Applies uniformly to
extract,list, andverify - The window this bounds contains no entry data — only metadata — so
it does not interact with
max_file_size/max_total_size. Draining an unread entry before the next header search is a separate concern (seeformats::tar_metadata_limit’s module docs) bounded by synthesized-byte accounting, not by this or any other quota value - Legitimate long-path/xattr metadata records are at most a few kilobytes each, and a GNU tar sparse file with heavy fragmentation can use up to a few thousand 512-byte extension blocks; either or both share this single budget (not “plus” each other), so the default leaves headroom for either shape, not necessarily both at their extremes simultaneously
- The real peak memory this bounds is roughly 5x the configured value
(GNU sparse extension blocks expand into multiple
EntryIorecords per block before the growth is charged against this budget), not an exact multiple — treat it as an order-of-magnitude ceiling, not a tight bound - Also caps the decoded bytes that follow the end-of-archive marker of a
compressed TAR, which extraction, listing and
verifywith integrity read to the end of the stream so the codec’s trailer (a gzip CRC) is checked. That cap never falls below 1 MiB (it coverstar -b 2048record padding), so lowering this value under 1 MiB does not tighten it; a longer tail is refused naming the effective cap
Default: 4 MiB (4,194,304 bytes)
max_decoder_memory: NonZeroU64Maximum memory in bytes a decoder may use for its dictionary or window.
The xz block header declares the LZMA2 dictionary size (up to 4 GiB)
and a zstd frame header declares its window (up to 2^41 bytes), so
without a limit a tiny archive can drive resident memory far beyond
what the output quotas allow. Archives that need more fail with
QuotaExceeded { DecoderMemory }.
- xz: bounds the decoder’s dictionary and state; applies to
extract,listandverifyof.tar.xz. - zstd: bounds the window to the largest power of two at or below this
value, at most 128 MiB (libzstd’s own ceiling), so a limit of 3 MiB
admits windows up to 2 MiB. It applies to
.tar.zstand to ZIP entries, which are checked from their frame headers: a ZIP archive with a larger window is refused byextract,listandverifybefore any entry is listed or extracted. Windows of 1 KiB or less are always admitted, and the decoder’s fixed state is not counted. - 7z: also admits the 7z decoder window; the lookahead of parallel 7z
decoding is budgeted separately by
parallel_decode.
Other codecs are bounded by their format (bzip2 blocks of at most 900 KB). Not exposed through the CLI or language bindings.
Default: 256 MiB (268,435,456 bytes)
compressed_member_allowance: NonZeroU64Base number of gzip members or bzip2 streams a compressed TAR may hold.
gzip -dc and bzip2 -dc decode every member, and each costs a decoder
setup, so a stream of empty members would burn time without producing
output the size quotas could count. Member n may start only while
n <= allowance, where allowance = compressed_member_allowance + decoded_bytes / 16 KiB; a stream that starts a member beyond that
fails with QuotaExceeded { CompressedMembers }. The output term lets
writers that flush a member per record (bgzf blocks are at most 64 KiB)
pass at any output size, provided they average 16 KiB or more per
member. A gzip or bzip2 stream averaging less than that over large
outputs must raise this value. Applies to extract, list and
verify of .tar.gz and .tar.bz2; xz and zstd are not governed by
it. Not exposed through the CLI or language bindings.
Default: 10,000 (100,000 for SecurityConfig::permissive)
parallel_decode: ParallelDecodeLookahead memory for decoding independent LZMA2 runs of a 7z block on worker threads.
Applies to extract and verify with integrity checking of 7z
archives. It is separate from max_decoder_memory, which keeps
bounding the decoder window. See ParallelDecode.
Default: Bounded at 128 MiB (1 GiB for SecurityConfig::permissive)
zip_consistency: ZipConsistencyPolicyHow ZIP archives with ambiguous structure are handled.
Default: ZipConsistencyPolicy::Enforce, including for
SecurityConfig::permissive. Pre-ZIP64 archives with more than
65535 entries (wrapped end-record count) and archives with orphaned
local headers, or with a central directory signature in a gap before an
entry (left by in-place updaters), are rejected under Enforce.
Implementations§
Source§impl SecurityConfig
impl SecurityConfig
Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
Creates a permissive configuration for trusted archives.
This configuration allows symlinks, hardlinks, absolute paths, and solid archives. Use only when extracting archives from trusted sources.
Sourcepub fn with_max_file_size(self, size: impl Into<Limit<NonZeroU64>>) -> Self
pub fn with_max_file_size(self, size: impl Into<Limit<NonZeroU64>>) -> Self
Sets the maximum size for a single extracted file in bytes.
§Examples
use exarch_core::SecurityConfig;
let config =
SecurityConfig::default().with_max_file_size(exarch_core::non_zero!(100 * 1024 * 1024));
assert!(config.max_file_size.admits(100 * 1024 * 1024));Sourcepub fn with_max_total_size(self, size: impl Into<Limit<NonZeroU64>>) -> Self
pub fn with_max_total_size(self, size: impl Into<Limit<NonZeroU64>>) -> Self
Sets the maximum total size for all extracted files in bytes.
§Examples
use exarch_core::SecurityConfig;
let config =
SecurityConfig::default().with_max_total_size(exarch_core::non_zero!(1024 * 1024 * 1024));
assert_eq!(config.max_total_size.ceiling(), 1024 * 1024 * 1024);Sourcepub fn with_max_compression_ratio(self, ratio: RatioLimit) -> Self
pub fn with_max_compression_ratio(self, ratio: RatioLimit) -> Self
Sets the maximum allowed compression ratio (uncompressed / compressed).
§Examples
use exarch_core::SecurityConfig;
let config =
SecurityConfig::default().with_max_compression_ratio(exarch_core::ratio_limit!(50.0));
assert_eq!(config.max_compression_ratio.get(), 50.0);Sourcepub fn with_max_file_count(self, count: impl Into<Limit<NonZeroUsize>>) -> Self
pub fn with_max_file_count(self, count: impl Into<Limit<NonZeroUsize>>) -> Self
Sets the maximum number of files that can be extracted.
§Examples
use exarch_core::SecurityConfig;
let config = SecurityConfig::default().with_max_file_count(exarch_core::non_zero!(500));
assert_eq!(config.max_file_count.ceiling(), 500);Sourcepub fn with_max_path_depth(self, depth: NonZeroUsize) -> Self
pub fn with_max_path_depth(self, depth: NonZeroUsize) -> Self
Sets the maximum path depth allowed.
§Examples
use exarch_core::SecurityConfig;
let config = SecurityConfig::default().with_max_path_depth(exarch_core::non_zero!(16));
assert_eq!(config.max_path_depth.get(), 16);Sourcepub fn with_allowed(self, allowed: AllowedFeatures) -> Self
pub fn with_allowed(self, allowed: AllowedFeatures) -> Self
Sets the feature flags controlling allowed archive features.
§Examples
use exarch_core::SecurityConfig;
use exarch_core::config::AllowedFeatures;
let features = AllowedFeatures::default();
let config = SecurityConfig::default().with_allowed(features);
assert!(!config.allowed.symlinks.is_allowed());Sourcepub fn with_allow_symlinks(self, allow: bool) -> Self
pub fn with_allow_symlinks(self, allow: bool) -> Self
Enables or disables symlinks in extracted archives.
§Examples
use exarch_core::SecurityConfig;
let config = SecurityConfig::default().with_allow_symlinks(true);
assert!(config.allowed.symlinks.is_allowed());Sourcepub fn with_allow_hardlinks(self, allow: bool) -> Self
pub fn with_allow_hardlinks(self, allow: bool) -> Self
Enables or disables hardlinks in extracted archives.
§Examples
use exarch_core::SecurityConfig;
let config = SecurityConfig::default().with_allow_hardlinks(true);
assert!(config.allowed.hardlinks.is_allowed());Sourcepub fn with_allow_absolute_paths(self, allow: bool) -> Self
pub fn with_allow_absolute_paths(self, allow: bool) -> Self
Enables or disables absolute paths in archive entries.
§Examples
use exarch_core::SecurityConfig;
let config = SecurityConfig::default().with_allow_absolute_paths(true);
assert!(config.allowed.absolute_paths.is_allowed());Sourcepub fn with_allow_world_writable(self, allow: bool) -> Self
pub fn with_allow_world_writable(self, allow: bool) -> Self
Enables or disables world-writable files.
§Examples
use exarch_core::SecurityConfig;
let config = SecurityConfig::default().with_allow_world_writable(true);
assert!(config.allowed.world_writable.is_allowed());Sourcepub fn with_allow_windows_reserved_names(self, allow: bool) -> Self
pub fn with_allow_windows_reserved_names(self, allow: bool) -> Self
Enables or disables Windows reserved device names (CON, NUL,
COM1, …) as path components. Only consulted on Windows.
§Examples
use exarch_core::SecurityConfig;
let config = SecurityConfig::default().with_allow_windows_reserved_names(true);
assert!(config.allowed.windows_reserved_names.is_allowed());Sourcepub fn with_preserve_permissions(self, preserve: bool) -> Self
pub fn with_preserve_permissions(self, preserve: bool) -> Self
Enables or disables preserving file permissions from the archive.
§Examples
use exarch_core::SecurityConfig;
let config = SecurityConfig::default().with_preserve_permissions(true);
assert!(config.preserve_permissions);Sourcepub fn with_allowed_extensions(self, extensions: Vec<Extension>) -> Self
pub fn with_allowed_extensions(self, extensions: Vec<Extension>) -> Self
Sets the list of allowed file extensions.
An empty list allows all extensions.
§Examples
use exarch_core::SecurityConfig;
let config = SecurityConfig::default()
.try_add_allowed_extension(".txt")?
.try_add_allowed_extension("pdf")?;
assert!(config.is_extension_allowed(Some("txt")));
assert!(!config.is_extension_allowed(Some("exe")));Sourcepub fn try_add_allowed_extension(self, extension: &str) -> Result<Self>
pub fn try_add_allowed_extension(self, extension: &str) -> Result<Self>
Appends one allowed extension, parsed by Extension.
§Errors
Returns crate::ArchiveError::InvalidConfiguration when extension
is not a usable extension.
Sourcepub fn try_add_banned_path_component(self, component: &str) -> Result<Self>
pub fn try_add_banned_path_component(self, component: &str) -> Result<Self>
Appends one banned path component, parsed by PathComponentName.
§Errors
Returns crate::ArchiveError::InvalidConfiguration when component
is not a usable path component name.
Sourcepub fn with_banned_path_components(
self,
components: Vec<PathComponentName>,
) -> Self
pub fn with_banned_path_components( self, components: Vec<PathComponentName>, ) -> Self
Sets the list of banned path components.
§Examples
use exarch_core::SecurityConfig;
let config = SecurityConfig::default()
.with_banned_path_components(Vec::new())
.try_add_banned_path_component(".git")?;
assert!(!config.is_path_component_allowed(".git"));
assert!(config.is_path_component_allowed(".ssh"));Sourcepub fn with_solid_archives(self, solid: SolidArchives) -> Self
pub fn with_solid_archives(self, solid: SolidArchives) -> Self
Sets the solid 7z archive policy together with its limits.
§Examples
use exarch_core::SecurityConfig;
use exarch_core::SolidArchives;
use exarch_core::SolidLimits;
let limits = SolidLimits::DEFAULT.with_max_block_memory(exarch_core::non_zero!(1 << 30));
let config = SecurityConfig::default().with_solid_archives(SolidArchives::Allow(limits));
assert_eq!(config.solid_archives.limits(), Some(limits));Sourcepub fn with_allow_solid_archives(self, allow: bool) -> Self
pub fn with_allow_solid_archives(self, allow: bool) -> Self
Enables or disables extraction from solid 7z archives.
true keeps the limits of an already admitted policy and otherwise
admits solid archives under SolidLimits::DEFAULT; a previous
Refuse therefore never carries limits over.
false refuses solid archives and drops any limits.
§Examples
use exarch_core::SecurityConfig;
let config = SecurityConfig::default().with_allow_solid_archives(true);
assert!(config.solid_archives.is_allowed());Sourcepub fn with_solid_limits(self, limits: SolidLimits) -> Result<Self>
pub fn with_solid_limits(self, limits: SolidLimits) -> Result<Self>
Sets the limits of an already admitted solid archive policy.
§Errors
Returns crate::ArchiveError::InvalidConfiguration naming
ConfigSetting::MaxSolidBlockMemory when solid archives are refused,
because the limits would be silently ignored.
§Examples
use exarch_core::SecurityConfig;
use exarch_core::SolidLimits;
let limits = SolidLimits::DEFAULT.with_max_block_memory(exarch_core::non_zero!(1 << 30));
assert!(SecurityConfig::default().with_solid_limits(limits).is_err());
let config = SecurityConfig::default()
.with_allow_solid_archives(true)
.with_solid_limits(limits)?;
assert_eq!(config.solid_archives.limits(), Some(limits));Sourcepub fn with_max_tar_metadata_bytes(self, size: NonZeroU64) -> Self
pub fn with_max_tar_metadata_bytes(self, size: NonZeroU64) -> Self
Sets the maximum bytes the TAR reader may consume for headers and metadata records (GNU long-name/long-link, PAX extended headers, GNU sparse extension blocks) in the gap between two consecutive entries.
§Examples
use exarch_core::SecurityConfig;
let config =
SecurityConfig::default().with_max_tar_metadata_bytes(exarch_core::non_zero!(64 * 1024));
assert_eq!(config.max_tar_metadata_bytes.get(), 64 * 1024);Sourcepub fn with_max_decoder_memory(self, size: NonZeroU64) -> Self
pub fn with_max_decoder_memory(self, size: NonZeroU64) -> Self
Sets the maximum memory a decoder may use, in bytes: the xz dictionary, and the zstd window as the largest power of two within it.
§Examples
use exarch_core::SecurityConfig;
let config =
SecurityConfig::default().with_max_decoder_memory(exarch_core::non_zero!(64 * 1024 * 1024));
assert_eq!(config.max_decoder_memory.get(), 64 * 1024 * 1024);Sourcepub fn with_compressed_member_allowance(self, base: NonZeroU64) -> Self
pub fn with_compressed_member_allowance(self, base: NonZeroU64) -> Self
Sets the base number of gzip members or bzip2 streams a compressed TAR may hold, before the allowance of one more per 16 KiB of output.
See compressed_member_allowance.
§Examples
use exarch_core::SecurityConfig;
use std::num::NonZeroU64;
let base = NonZeroU64::new(50_000).unwrap();
let config = SecurityConfig::default().with_compressed_member_allowance(base);
assert_eq!(config.compressed_member_allowance, base);Sourcepub fn with_parallel_decode(self, mode: ParallelDecode) -> Self
pub fn with_parallel_decode(self, mode: ParallelDecode) -> Self
Sets the lookahead memory for parallel 7z LZMA2 decoding.
§Examples
use exarch_core::ParallelDecode;
use exarch_core::SecurityConfig;
let config = SecurityConfig::default().with_parallel_decode(ParallelDecode::Sequential);
assert_eq!(config.parallel_decode, ParallelDecode::Sequential);Sourcepub fn with_zip_consistency(self, policy: ZipConsistencyPolicy) -> Self
pub fn with_zip_consistency(self, policy: ZipConsistencyPolicy) -> Self
Sets how ZIP archives with ambiguous structure are handled.
§Examples
use exarch_core::SecurityConfig;
use exarch_core::ZipConsistencyPolicy;
let config = SecurityConfig::default().with_zip_consistency(ZipConsistencyPolicy::Ignore);
assert_eq!(config.zip_consistency, ZipConsistencyPolicy::Ignore);Source§impl SecurityConfig
Read-only queries.
impl SecurityConfig
Read-only queries.
Sourcepub fn is_path_component_allowed(&self, component: &str) -> bool
pub fn is_path_component_allowed(&self, component: &str) -> bool
Validates whether a path component is allowed.
Comparison is case-insensitive to prevent bypass on case-insensitive filesystems (Windows, macOS default).
Sourcepub fn is_extension_allowed(&self, extension: Option<&str>) -> bool
pub fn is_extension_allowed(&self, extension: Option<&str>) -> bool
Returns true if a file with the given optional extension may be
extracted.
When allowed_extensions is empty, all files are permitted. When it is
non-empty, only listed extensions are permitted (ignoring ASCII case),
and extension being None (the file has no extension) is not
allowed.
§Examples
use exarch_core::SecurityConfig;
let config = SecurityConfig::default().try_add_allowed_extension("txt")?;
assert!(config.is_extension_allowed(Some("txt")));
assert!(!config.is_extension_allowed(Some("exe")));
// Files without an extension are blocked when the allowlist is non-empty.
assert!(!config.is_extension_allowed(None));
// Empty allowlist permits everything, including extension-less files.
let permissive = SecurityConfig::default();
assert!(permissive.is_extension_allowed(None));Trait Implementations§
Source§impl Clone for SecurityConfig
impl Clone for SecurityConfig
Source§impl Debug for SecurityConfig
impl Debug for SecurityConfig
Source§impl Default for SecurityConfig
impl Default for SecurityConfig
Source§fn default() -> Self
fn default() -> Self
Creates a SecurityConfig with secure default settings.
Default values:
max_file_size: 50 MBmax_total_size: 500 MBmax_compression_ratio: 100.0max_file_count: 10,000max_path_depth: 32allowed: All features refused (deny-by-default)preserve_permissions: falseallowed_extensions: empty (allow all)banned_path_components:[".git", ".ssh", ".gnupg", ".aws", ".kube", ".docker", ".env"]solid_archives:SolidArchives::Refuse(solid archives rejected)max_tar_metadata_bytes: 4 MiBmax_decoder_memory: 256 MiBcompressed_member_allowance: 10,000parallel_decode:Boundedat 128 MiBzip_consistency:Enforce