An archive entry is a request to create a filesystem object at a sender-chosen path. Checking the archive filename or its compressed size leaves the entry paths, links, expanded output, and partial-result lifecycle unresolved. Review extraction as a sequence of authorized writes whose output remains unavailable until the whole operation succeeds.
This design explanation follows a synthetic document import. The service needs ordinary files and directories, accepts no links or devices, and publishes a completed import as one logical result. It does not provide an extractor implementation or claim that a particular library has been integration-tested on the reader's operating system.
Treat entry names as requested writes
The OWASP path traversal guidance describes archive entries escaping an extraction destination through relative paths, absolute paths, or links. The protected asset is everything the worker can write outside its assigned import directory. The attacker controls the archive's names, entry types, ordering, and compressed content.
For the worked scenario, a valid archive contains manual/intro.txt and manual/images/diagram.png. An entry named ../outside.txt must reject the import. So must an absolute destination. The rejection criterion is containment within the assigned root, not whether a suspicious substring happens to appear in the original name.
Path interpretation depends on the platform and the archive format. Windows drive-relative names, alternate separators, device names, and trailing punctuation complicate a policy written for POSIX paths. Define the allowed name grammar and use extraction facilities designed for the deployment platform. Merely replacing backslashes or stripping leading dots can transform hostile input into a different unintended write.
Contain filesystem traversal, not only strings
A lexical containment check answers whether a normalized path appears to remain inside a root. It does not prove that opening the path will stay there. A symlink in a parent component can redirect a later write, and a concurrent actor can change filesystem state after a check.
In the synthetic archive, reject a link entry named manual/latest even if its own name appears harmless. A later file under that name could otherwise traverse the link. Hard links need an explicit policy too. Because the import requires only ordinary documents, denying unsupported entry types is simpler to verify than preserving them with partially understood behavior.
Create a fresh extraction directory that untrusted users and unrelated workers cannot modify. Use the library's maintained restrictive extraction mode and containment-aware file operations where supported. Run the worker with filesystem permissions limited to its job. These controls address different failure paths; restrictive process authority bounds damage if the extraction layer still makes a mistake.
Reject duplicate destinations under the filesystem's actual comparison rules. Two entries that differ only by case may collide on the target system. An ordinary file followed by a directory at the same destination can also make ordering affect the result. A document importer benefits from a deterministic refusal instead of accepting whichever entry happened to overwrite another.
Enforce budgets while bytes expand
Compressed upload size is only an ingress budget. Give the extraction operation separate limits for total expanded bytes, bytes per file, entry count, path depth, processing time, and storage use. Those limits are product choices based on the document formats and worker capacity, not universal constants.
Do not trust an entry's declared expanded size as the only enforcement input. Count actual output as it is produced, and stop before exceeding the assigned budget. A preliminary metadata pass can reject obvious violations early, but it cannot replace enforcement during the write.
Suppose the synthetic importer allows 20 MiB of expanded documents. Entry one produces 12 MiB and entry two reaches another 8 MiB before more output remains. The next output must be refused without writing past the boundary. Reject the whole import and discard its isolated partial result. An error after the limit is exceeded is evidence of detection, not evidence that the budget was enforced.
Nested archives need a deliberate rule. A document importer can store them as inert files or reject them. Automatically expanding them introduces another processing tree whose aggregate work must remain within the same job budget. A timeout also needs cancellation that reaches the worker; returning an HTTP error while expansion continues does not release the resource.
Publish only a completed result
Model the import as received, extracting, validated, and published, with rejected and abandoned outcomes. Ordinary users should see none of the extracting directory. A traversal refusal, malformed entry, quota failure, or worker interruption must leave no import available through the retrieval API.
Publication needs a platform-supported operation that fits the storage system. A local same-filesystem rename may suit one design; an object store may need a manifest or pointer update after all objects are verified. Do not assume a directory operation is atomic across filesystems or that an object prefix acts like a transactional directory.
Exercise failures after the first successful write, immediately before publication, and after publication acknowledgment is lost. Assert both absence of unauthorized files and absence of a published partial import. Reconcile an unknown publication outcome through an operation identity rather than blindly repeating extraction into an existing directory.
Retain bounded diagnostic metadata such as the rejected entry category and job identity, without echoing attacker-controlled paths into an unsafe interface. Clean abandoned directories through a scoped job that verifies its target and cannot traverse user-created links. The upload workflow guide covers the surrounding quarantine and retrieval boundary.
Before using an extraction library, run this scenario against its exact version and deployment filesystem. The source-reviewed design does not establish that integration result. Approval should depend on observable containment, enforced expansion limits, and a retrieval boundary that cannot expose output from any rejected or interrupted import.
Was this guide useful?
Your rating helps us prioritize clearer, more practical technical content.
Review diffs, run checks, and prepare the release in Arezgit.
Keep Git review, security scanning, API checks, database inspection, and release preparation together in one local desktop application.
Explore Arezgit