Skip to main content

CVE-2021-32842: 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:10:10 UTC)
Source: CVE
Vendor/Project: icsharpcode
Product: sharpziplib

Description

SharpZipLib (or #ziplib) is a Zip, GZip, Tar and BZip2 library. Starting version 1.0.0 and prior to version 1.3.3, a check was added if the destination file is under a destination directory. However, it is not enforced that `_baseDirectory` ends with slash. If the _baseDirectory is not slash terminated like `/home/user/dir` it is possible to create a file with a name thats begins as the destination directory one level up from the directory, i.e. `/home/user/dir.sh`. Because of the file name and destination directory constraints, the arbitrary file creation impact is limited and depends on the use case. Version 1.3.3 fixed this vulnerability.

AI-Powered Analysis

AILast updated: 06/22/2025, 04:35:41 UTC

Technical Analysis

CVE-2021-32842 is a path traversal vulnerability identified in the icsharpcode SharpZipLib library, which is a widely used open-source compression library supporting Zip, GZip, Tar, and BZip2 formats. The vulnerability affects versions starting from 1.0.0 up to, but not including, 1.3.3. The root cause lies in improper validation of the destination directory path when extracting archive contents. Specifically, the library added a check to ensure that extracted files reside within a specified destination directory. However, this check did not enforce that the base directory path ends with a trailing slash. Without this enforcement, an attacker can craft archive entries with filenames that begin similarly to the destination directory but actually reside outside it, for example, if the base directory is set to "/home/user/dir" (without trailing slash), a file named "dir.sh" could be created at "/home/user/dir.sh", effectively escaping the intended extraction directory. This improper limitation of pathname to a restricted directory (CWE-22) can lead to arbitrary file creation outside the intended directory. The impact of this vulnerability depends heavily on the context in which SharpZipLib is used, including what files are extracted and the privileges of the process performing extraction. The vulnerability was fixed in version 1.3.3 by enforcing the trailing slash requirement on the base directory path, thereby preventing directory traversal via crafted filenames. There are no known exploits in the wild reported to date. The vulnerability is classified as medium severity due to its limited impact scope and dependency on specific use cases and configurations.

Potential Impact

For European organizations, the impact of CVE-2021-32842 can vary based on how SharpZipLib is integrated into their software stack. Organizations using applications or services that rely on vulnerable versions of SharpZipLib for decompressing user-supplied archives may be at risk of arbitrary file creation outside the intended extraction directory. This can lead to overwriting or creating files in sensitive locations, potentially enabling code execution, privilege escalation, or disruption of service if critical system or application files are affected. The confidentiality, integrity, and availability of systems could be compromised if attackers leverage this vulnerability to place malicious payloads or disrupt normal operations. However, the actual risk is mitigated if the extraction process runs with limited privileges or in sandboxed environments. European enterprises in sectors such as software development, cloud services, and any industry relying on .NET or Mono-based applications (where SharpZipLib is commonly used) should be particularly vigilant. The absence of known exploits suggests a lower immediate threat, but the potential for targeted attacks remains, especially in environments where untrusted archives are processed automatically.

Mitigation Recommendations

1. Upgrade to SharpZipLib version 1.3.3 or later, where the vulnerability is fixed by enforcing trailing slash checks on base directories. 2. Implement strict input validation and sanitization on archive files before extraction, including verifying filenames for path traversal patterns. 3. Run extraction processes with the least privilege necessary, ideally in isolated or sandboxed environments to limit the impact of any arbitrary file creation. 4. Use application-level controls to restrict archive extraction to trusted sources only. 5. Monitor file system changes in directories used for extraction to detect unexpected file creations or modifications. 6. For developers, explicitly ensure that base directory paths used in extraction routines are normalized and end with a trailing slash to prevent traversal. 7. Incorporate security testing and code reviews focusing on archive handling components to detect similar path traversal issues. 8. If upgrading is not immediately feasible, consider patching or applying custom validation logic to enforce directory constraints robustly.

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: 682d9848c4522896dcbf60cb

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

Last enriched: 6/22/2025, 4:35:41 AM

Last updated: 8/1/2025, 6:42:22 PM

Views: 16

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