GHSA-jp7f-grcv-6mjf

Suggest an improvement
Source
https://github.com/advisories/GHSA-jp7f-grcv-6mjf
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2021/09/GHSA-jp7f-grcv-6mjf/GHSA-jp7f-grcv-6mjf.json
JSON Data
https://api.test.osv.dev/v1/vulns/GHSA-jp7f-grcv-6mjf
Aliases
Published
2021-09-20T19:53:42Z
Modified
2024-07-08T14:48:06.643018Z
Severity
  • 4.3 (Medium) CVSS_V3 - CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N CVSS Calculator
  • 5.3 (Medium) CVSS_V4 - CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N CVSS Calculator
Summary
Partial path traversal in sharpcompress
Details

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.

Database specific
{
    "nvd_published_at": "2021-09-16T15:15:00Z",
    "cwe_ids": [
        "CWE-22"
    ],
    "severity": "MODERATE",
    "github_reviewed": true,
    "github_reviewed_at": "2021-09-17T18:37:10Z"
}
References

Affected packages

NuGet / SharpCompress

Package

Name
SharpCompress
View open source insights on deps.dev
Purl
pkg:nuget/SharpCompress

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
0.29

Affected versions

0.*

0.2.0
0.3.0
0.4.0
0.5.0
0.6.0
0.7.0
0.8.0
0.8.1
0.8.2
0.9.0
0.10.0
0.10.1
0.10.1.1
0.10.1.3
0.10.2
0.10.3
0.11.0
0.11.1
0.11.2
0.11.3
0.11.4
0.11.5
0.11.6
0.12.0
0.12.1
0.12.2
0.12.3
0.12.4
0.13.0
0.13.1
0.14.0
0.14.1
0.15.0
0.15.1
0.15.2
0.16.0
0.16.1
0.16.2
0.17.0
0.17.1
0.18.0
0.18.1
0.18.2
0.19.0
0.19.1
0.19.2
0.20.0
0.21.0
0.21.1
0.22.0
0.23.0
0.24.0
0.25.0
0.25.1
0.26.0
0.27.0
0.27.1
0.28.0
0.28.1
0.28.2
0.28.3

Ecosystem specific

{
    "affected_functions": [
        "WriteEntryToDirectory"
    ]
}