CVE-2021-32841: CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') in icsharpcode sharpziplib
SharpZipLib (or #ziplib) is a Zip, GZip, Tar and BZip2 library. Starting version 1.3.0 and prior to version 1.3.3, a check was added if the destination file is under destination directory. However, it is not enforced that `destDir` ends with slash. If the `destDir` is not slash terminated like `/home/user/dir` it is possible to create a file with a name thats begins with the destination 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 contains a patch for this vulnerability.
AI Analysis
Technical Summary
CVE-2021-32841 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.3.0 up to but not including 1.3.3. The root cause lies in the improper validation of the destination directory path when extracting archive contents. Specifically, the library added a check to ensure that extracted files reside under the specified destination directory. However, this check fails to enforce that the destination directory path ends with a trailing slash. Without this trailing slash, an attacker can craft archive entries with filenames that begin with the destination directory path but actually escape it by appending additional characters (e.g., if the destination directory is '/home/user/dir', a file named 'dir.sh' would be extracted to '/home/user/dir.sh', outside the intended directory). This improper limitation of pathname (CWE-22) allows for arbitrary file creation outside the intended extraction directory. The impact of this vulnerability depends heavily on the context in which SharpZipLib is used, as it requires the application to extract untrusted archives and not properly sanitize or enforce directory constraints. The vulnerability was patched in version 1.3.3 by ensuring the destination directory path is properly normalized and enforced with a trailing slash. There are no known exploits in the wild reported to date, and no authentication or user interaction is explicitly required for exploitation if the application processes untrusted archives automatically. However, exploitation requires the ability to supply crafted archive files to the vulnerable application.
Potential Impact
For European organizations, the impact of CVE-2021-32841 can vary depending on the deployment of SharpZipLib within their software stack. Organizations using applications that rely on vulnerable versions of SharpZipLib for archive extraction may be at risk of arbitrary file creation outside intended directories. This could lead to overwriting critical files, placing malicious executables or scripts, or otherwise compromising system integrity. The confidentiality impact is generally limited unless the attacker can overwrite files that control access or leak sensitive data. The integrity impact is more significant, as attackers could modify or inject files that alter application behavior or escalate privileges. Availability impact is possible if critical files are overwritten or system stability is affected. Since SharpZipLib is used in many .NET applications, including enterprise software and custom tools, European organizations in sectors such as finance, manufacturing, and government that rely on such software could be affected. The risk is higher in automated environments where archive extraction is performed without manual inspection. Given the lack of known exploits, the threat is currently moderate but could increase if attackers develop reliable exploitation techniques. Additionally, supply chain risks exist if third-party software packages include vulnerable SharpZipLib versions.
Mitigation Recommendations
1. Upgrade SharpZipLib to version 1.3.3 or later, which contains the official patch addressing the path traversal issue. 2. Implement strict input validation and sanitization on archive files before extraction, including verifying filenames do not contain path traversal sequences or unexpected characters. 3. Use sandboxed or isolated environments for archive extraction to limit potential damage from arbitrary file creation. 4. Employ application-level controls to restrict file write permissions to only necessary directories and prevent overwriting critical system or application files. 5. Monitor file system changes in directories used for archive extraction to detect suspicious activity. 6. For developers, consider using alternative libraries with stronger security guarantees or implement custom extraction logic with robust path normalization. 7. Conduct security code reviews and penetration testing focused on archive handling components to identify similar vulnerabilities. 8. Educate users and administrators about the risks of processing untrusted archives and enforce policies to limit such actions.
Affected Countries
Germany, France, United Kingdom, Netherlands, Italy, Spain, Poland, Sweden, Belgium, Austria
CVE-2021-32841: CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') in icsharpcode sharpziplib
Description
SharpZipLib (or #ziplib) is a Zip, GZip, Tar and BZip2 library. Starting version 1.3.0 and prior to version 1.3.3, a check was added if the destination file is under destination directory. However, it is not enforced that `destDir` ends with slash. If the `destDir` is not slash terminated like `/home/user/dir` it is possible to create a file with a name thats begins with the destination 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 contains a patch for this vulnerability.
AI-Powered Analysis
Technical Analysis
CVE-2021-32841 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.3.0 up to but not including 1.3.3. The root cause lies in the improper validation of the destination directory path when extracting archive contents. Specifically, the library added a check to ensure that extracted files reside under the specified destination directory. However, this check fails to enforce that the destination directory path ends with a trailing slash. Without this trailing slash, an attacker can craft archive entries with filenames that begin with the destination directory path but actually escape it by appending additional characters (e.g., if the destination directory is '/home/user/dir', a file named 'dir.sh' would be extracted to '/home/user/dir.sh', outside the intended directory). This improper limitation of pathname (CWE-22) allows for arbitrary file creation outside the intended extraction directory. The impact of this vulnerability depends heavily on the context in which SharpZipLib is used, as it requires the application to extract untrusted archives and not properly sanitize or enforce directory constraints. The vulnerability was patched in version 1.3.3 by ensuring the destination directory path is properly normalized and enforced with a trailing slash. There are no known exploits in the wild reported to date, and no authentication or user interaction is explicitly required for exploitation if the application processes untrusted archives automatically. However, exploitation requires the ability to supply crafted archive files to the vulnerable application.
Potential Impact
For European organizations, the impact of CVE-2021-32841 can vary depending on the deployment of SharpZipLib within their software stack. Organizations using applications that rely on vulnerable versions of SharpZipLib for archive extraction may be at risk of arbitrary file creation outside intended directories. This could lead to overwriting critical files, placing malicious executables or scripts, or otherwise compromising system integrity. The confidentiality impact is generally limited unless the attacker can overwrite files that control access or leak sensitive data. The integrity impact is more significant, as attackers could modify or inject files that alter application behavior or escalate privileges. Availability impact is possible if critical files are overwritten or system stability is affected. Since SharpZipLib is used in many .NET applications, including enterprise software and custom tools, European organizations in sectors such as finance, manufacturing, and government that rely on such software could be affected. The risk is higher in automated environments where archive extraction is performed without manual inspection. Given the lack of known exploits, the threat is currently moderate but could increase if attackers develop reliable exploitation techniques. Additionally, supply chain risks exist if third-party software packages include vulnerable SharpZipLib versions.
Mitigation Recommendations
1. Upgrade SharpZipLib to version 1.3.3 or later, which contains the official patch addressing the path traversal issue. 2. Implement strict input validation and sanitization on archive files before extraction, including verifying filenames do not contain path traversal sequences or unexpected characters. 3. Use sandboxed or isolated environments for archive extraction to limit potential damage from arbitrary file creation. 4. Employ application-level controls to restrict file write permissions to only necessary directories and prevent overwriting critical system or application files. 5. Monitor file system changes in directories used for archive extraction to detect suspicious activity. 6. For developers, consider using alternative libraries with stronger security guarantees or implement custom extraction logic with robust path normalization. 7. Conduct security code reviews and penetration testing focused on archive handling components to identify similar vulnerabilities. 8. Educate users and administrators about the risks of processing untrusted archives and enforce policies to limit such actions.
For access to advanced analysis and higher rate limits, contact root@offseq.com
Technical Details
- Data Version
- 5.1
- Assigner Short Name
- GitHub_M
- Date Reserved
- 2021-05-12T00:00:00.000Z
- Cisa Enriched
- true
Threat ID: 682d9848c4522896dcbf60be
Added to database: 5/21/2025, 9:09:28 AM
Last enriched: 6/22/2025, 4:35:53 AM
Last updated: 8/3/2025, 3:49:16 AM
Views: 20
Related Threats
CVE-2025-8959: CWE-59: Improper Link Resolution Before File Access (Link Following) in HashiCorp Shared library
HighCVE-2025-44201
LowCVE-2025-36088: CWE-79 Improper Neutralization of Input During Web Page Generation (XSS or 'Cross-site Scripting') in IBM Storage TS4500 Library
MediumCVE-2025-43490: CWE-59 Improper Link Resolution Before File Access ('Link Following') in HP, Inc. HP Hotkey Support Software
MediumCVE-2025-9060: CWE-20 Improper Input Validation in MSoft MFlash
CriticalActions
Updates to AI analysis are available only with a Pro account. Contact root@offseq.com for access.
External Links
Need enhanced features?
Contact root@offseq.com for Pro access with improved analysis and higher rate limits.