Medium

Partial path traversal in sharpcompress

  • Disclosed: 20.09.2021
  • Updated: 11.10.2026 11:23

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<string, ExtractionOptions?> 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.

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
.NET (NuGet) SharpCompress < 0.29 0.29

References

CVSS score 4.3/10
CVSS vector
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N
Weakness (CWE)
CWE-22
Platform
.NET (NuGet)
Package
SharpCompress
Disclosed
20.09.2021
Updated
11.10.2026 11:23

Sources and licenses

OSV / GitHub Advisory Database - GHSA-jp7f-grcv-6mjf - CC BY 4.0

Vulnerability history: SharpCompress

All published vulnerabilities of this package (.NET (NuGet)), newest first. Shows whether this is a one-off slip or a package that needs watching.

Total entries
3
First → latest
09.2019 05.2026
Without a fix
0
Exploited in attacks
0

Severity breakdown

  • Medium 3

Disclosures per year

  1. 2019: 1
  2. 2020: 0
  3. 2021: 1
  4. 2022: 0
  5. 2023: 0
  6. 2024: 0
  7. 2025: 0
  8. 2026: 1
  1. Partial path traversal in sharpcompress this entry
    Medium · 4.3 CVE-2021-39208 < 0.29 0.29
  2. Medium · 5.5 CVE-2018-1002206 < 0.21.0 0.21.0

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.