CVE-2021-39208: SharpCompress Path Traversal Vulnerability
MODERATECVE-2021-39208 is a MODERATE (CVSS 4.3) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting SharpCompress libraries in the NuGet ecosystem. The issue involves partial path traversal in sharpcompress. Remediation is available by upgrading affected packages to version 0.29.
CVE-2021-39208 at a Glance
Security Impact
CVSS: 4.3
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N).
How to Fix CVE-2021-39208
To remediate this vulnerability, upgrade all affected SharpCompress dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
Upgrade SharpCompress to 0.29
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
inspect dependencies for SharpCompress
How to Check if You Are Affected
To determine whether your application is affected by CVE-2021-39208, inspect your project dependencies for SharpCompress:
inspect dependencies for SharpCompress
Analyze the terminal output to locate any version of SharpCompress in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.29), your application is affected.
Note: Verify declared build manifests and deployed runtime container environments.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In SharpCompress, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2021-39208 Affected SharpCompress Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
SharpCompress
|
NuGet |
< 0.29
|
0.29
|
References
Frequently Asked Questions
What is CVE-2021-39208?
Which SharpCompress versions are affected?
What version fixes CVE-2021-39208?
Is SharpCompress affected?
What is the CVSS score of CVE-2021-39208?
What CWE is associated with CVE-2021-39208?
How can I check NuGet dependencies for CVE-2021-39208?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-jp7f-grcv-6mjf",
"modified" : "2024-07-08T14:33:23Z",
"published" : "2021-09-20T19:53:42Z",
"aliases" : [ "CVE-2021-39208" ],
"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:\n\n```csharp\npublic static void WriteEntryToDirectory(IEntry entry,\n string destinationDirectory,\n ExtractionOptions? options,\n Action<string, ExtractionOptions?> write)\n{\n string destinationFileName;\n string file = Path.GetFileName(entry.Key);\n string fullDestinationDirectoryPath = Path.GetFullPath(destinationDirectory);\n...\n throw new ExtractionException(\"Entry is trying to write a file outside of the destination directory.\");\n}\n```\n\nIf 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.\n\n#### Impact\nBecause of the file name and destination directory constraints the arbitrary file creation impact is limited and depends on the use case.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N"
}, {
"type" : "CVSS_V4",
"score" : "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"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "NuGet",
"name" : "SharpCompress"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "0.29"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/adamhathcock/sharpcompress/security/advisories/GHSA-jp7f-grcv-6mjf"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-39208"
}, {
"type" : "WEB",
"url" : "https://github.com/adamhathcock/sharpcompress/pull/614"
}, {
"type" : "WEB",
"url" : "https://github.com/adamhathcock/sharpcompress/commit/ea5c8dc06314c7a5068e7901c51a625224d2b288"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/adamhathcock/sharpcompress"
}, {
"type" : "WEB",
"url" : "https://github.com/adamhathcock/sharpcompress/releases/tag/0.29.0"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-22" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2021-09-17T18:37:10Z",
"nvd_published_at" : "2021-09-16T15:15:00Z"
}
}