What’s Vulnerable › Vulnerabilities
CVE-2021-39208: WriteEntryToDirectory used for an archive extraction is vulnerable to partial path traversal.
- Severity: medium (CVSS 4.0 v2.0)
- Exploited in the wild: not listed in CISA KEV
- EPSS: 1.2% probability of exploitation in the next 30 days
- Public exploit or detection template: yes
- Published: 2021-09-16 · updated 2026-06-17
- Weakness: CWE-22
Description
SharpCompress is a fully managed C# library to deal with many compression types and formats. Versions prior to 0.29.0 are vulnerable to partial path traversal. SharpCompress recreates a hierarchy of directories under destinationDirectory if ExtractFullPath is set to true in options. In order to prevent extraction outside the destination directory the destinationFileName path is verified to begin with fullDestinationDirectoryPath. However, prior to version 0.29.0, it is not enforced that fullDestinationDirectoryPath ends with slash. If the destinationDirectory 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. This issue is fixed in SharpCompress version 0.29.0.
Affected products
- Sharpcompress Project Sharpcompress: before 0.29.0 — fixed in 0.29.0
How to fix
Upgrade to a fixed version: Sharpcompress Project Sharpcompress 0.29.0. Check the vendor advisory for mitigations.
References
- https://github.com/adamhathcock/sharpcompress/pull/614
- https://github.com/adamhathcock/sharpcompress/releases/tag/0.29.0
- https://github.com/adamhathcock/sharpcompress/security/advisories/GHSA-jp7f-grcv-6mjf
- https://github.com/adamhathcock/sharpcompress/pull/614
- https://github.com/adamhathcock/sharpcompress/releases/tag/0.29.0
- https://github.com/adamhathcock/sharpcompress/security/advisories/GHSA-jp7f-grcv-6mjf
Get alerted when CVE-2021-39208 or the next vulnerability affects your stack