Skip to content

Partial path traversal in sharpcompress

Moderate severity GitHub Reviewed Published Sep 16, 2021 in adamhathcock/sharpcompress • Updated Mar 24, 2023

Package

nuget sharpcompress (NuGet)

Affected versions

< 0.29

Patched versions

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:

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.

References

@adamhathcock adamhathcock published to adamhathcock/sharpcompress Sep 16, 2021
Published by the National Vulnerability Database Sep 16, 2021
Reviewed Sep 17, 2021
Published to the GitHub Advisory Database Sep 20, 2021
Last updated Mar 24, 2023

Severity

Moderate
4.3
/ 10

CVSS base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
Low
Availability
None
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N

Weaknesses

CVE ID

CVE-2021-39208

GHSA ID

GHSA-jp7f-grcv-6mjf

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.