Skip to main content

CVE-2021-32840: CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') in icsharpcode sharpziplib

Medium
Published: Wed Jan 26 2022 (01/26/2022, 21:05:10 UTC)
Source: CVE
Vendor/Project: icsharpcode
Product: sharpziplib

Description

SharpZipLib (or #ziplib) is a Zip, GZip, Tar and BZip2 library. Prior to version 1.3.3, a TAR file entry `../evil.txt` may be extracted in the parent directory of `destFolder`. This leads to arbitrary file write that may lead to code execution. The vulnerability was patched in version 1.3.3.

AI-Powered Analysis

AILast updated: 06/22/2025, 04:36:04 UTC

Technical Analysis

CVE-2021-32840 is a path traversal vulnerability identified in the icsharpcode SharpZipLib, a widely used open-source library for handling compressed archive formats such as Zip, GZip, Tar, and BZip2. The vulnerability exists in versions prior to 1.3.3 of SharpZipLib and specifically affects the extraction of TAR archive entries. An attacker can craft a malicious TAR file containing entries with relative path components like '../evil.txt'. When such an archive is extracted, the library fails to properly restrict the extraction path to the intended destination directory, allowing files to be written outside the target folder. This arbitrary file write capability can be leveraged by an attacker to overwrite critical files on the host system, potentially leading to remote code execution if executable files or scripts are overwritten or planted. The vulnerability is classified under CWE-22 (Improper Limitation of a Pathname to a Restricted Directory), which is a common weakness related to insufficient validation of file paths during extraction or file operations. The issue was addressed and patched in SharpZipLib version 1.3.3. No known exploits have been reported in the wild to date, but the vulnerability remains a significant risk for applications and services that use vulnerable versions of SharpZipLib to process untrusted TAR archives. Given the library’s use in various .NET applications, the attack surface includes any system that automatically extracts TAR files using SharpZipLib without additional path validation or sandboxing controls.

Potential Impact

For European organizations, the impact of this vulnerability can be substantial, especially for those relying on software that incorporates SharpZipLib for archive extraction. Successful exploitation can lead to arbitrary file writes outside the intended directory, enabling attackers to overwrite configuration files, plant malicious executables, or modify scripts, potentially resulting in remote code execution. This compromises confidentiality, integrity, and availability of affected systems. Sectors such as finance, healthcare, manufacturing, and government agencies that process large volumes of compressed data or automate archive extraction are particularly at risk. The ability to execute code remotely could facilitate lateral movement within networks, data exfiltration, or disruption of critical services. Since SharpZipLib is commonly used in .NET environments, organizations with extensive Microsoft technology stacks may be more exposed. The absence of known exploits in the wild reduces immediate risk but does not eliminate the threat, especially as threat actors often reverse-engineer patches to develop exploits. Additionally, supply chain risks exist if third-party software vendors embed vulnerable versions of SharpZipLib in their products distributed across Europe.

Mitigation Recommendations

1. Immediate upgrade to SharpZipLib version 1.3.3 or later in all applications and services that utilize this library for archive extraction. 2. Implement additional path sanitization and validation checks before extracting archive entries, ensuring that no file paths contain directory traversal sequences or resolve outside the intended extraction directory. 3. Employ sandboxing or containerization techniques to isolate archive extraction processes, limiting the potential impact of arbitrary file writes. 4. Conduct thorough code audits and dependency scans to identify and remediate usage of vulnerable SharpZipLib versions in internal and third-party software. 5. Monitor file system changes and application logs for unusual write operations or unexpected file creations outside designated directories. 6. Educate developers and DevOps teams about secure handling of archive files and the risks of path traversal vulnerabilities. 7. For organizations distributing software that includes SharpZipLib, ensure that all releases are updated and communicate the importance of patching to downstream users. 8. Consider implementing application whitelisting and integrity verification mechanisms to detect unauthorized file modifications resulting from exploitation attempts.

Need more detailed analysis?Get Pro

Technical Details

Data Version
5.1
Assigner Short Name
GitHub_M
Date Reserved
2021-05-12T00:00:00.000Z
Cisa Enriched
true

Threat ID: 682d9848c4522896dcbf60ba

Added to database: 5/21/2025, 9:09:28 AM

Last enriched: 6/22/2025, 4:36:04 AM

Last updated: 8/16/2025, 4:59:35 AM

Views: 15

Actions

PRO

Updates to AI analysis are available only with a Pro account. Contact root@offseq.com for access.

Please log in to the Console to use AI analysis features.

Need enhanced features?

Contact root@offseq.com for Pro access with improved analysis and higher rate limits.

Latest Threats