GitHub Advisoryadvisory · NuGet
GHSA-jp7f-grcv-6mjf Partial path traversal in sharpcompress
MEDIUM
Official page ↗
- Aliases
- CVE-2021-39208
- Ecosystem
- NuGet
- Packages
- SharpCompress
- Severity
- Moderate
- CVSS vector
- CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N
- Weaknesses
- CWE-22
- Reviewed
- 2021-09-17
Affected packages
• NuGet SharpCompress: < 0.29 → fixed in 0.29
Description
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 it is not enforced that fullDestinationDirectoryPath ends with slash:
```csharp
public static void WriteEntryToDirectory(IEntry entry,
string destinationDirectory,
ExtractionOptions? options,
Action write)
{
string destinationFileName;
string file = Path.GetFileName(entry.Key);
string fullDestinationDirectoryPath = Path.GetFullPath(destinationDirectory);
...
throw new ExtractionException("Entry is trying to write a file outside of the destination directory.");
}
```
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.
Impact
Because of the file name and destination directory constraints the arbitrary file creation impact is limited and depends on the use case.
Related
Alias · CVE (1)
- CVE-2021-39208 SharpCompress is a fully managed C# library to deal with many compression types and formats. vulnerability
Weakness · CWE (1)
- CWE-22 Improper Limitation of a Pathname to a Restricted Directory weakness
References
- https://github.com/adamhathcock/sharpcompress/security/advisories/GHSA-jp7f-grcv-6mjf web
- https://nvd.nist.gov/vuln/detail/CVE-2021-39208 advisory
- https://github.com/adamhathcock/sharpcompress/pull/614 web
- https://github.com/adamhathcock/sharpcompress/commit/ea5c8dc06314c7a5068e7901c51a625224d2b288 web
- https://github.com/adamhathcock/sharpcompress package
- https://github.com/adamhathcock/sharpcompress/releases/tag/0.29.0 web