4.3medium
WriteEntryToDirectory used for an archive extraction is vulnerable to partial path traversal.
- Severity
- 4.3medium CVSS:3.1 by GitHub_M
- Exploit likelihood
- 1.19% (higher than 68% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-jp7f-grcv-6mjf
Description
SharpCompress is a fully managed C# library to deal with many compression types and formats. Versions prior to 0.29.0 are vulnerable to partial path traversal. 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, prior to version 0.29.0, it is not enforced that fullDestinationDirectoryPath ends with slash. 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`. Because of the file name and destination directory constraints the arbitrary file creation impact is limited and depends on the use case. This issue is fixed in SharpCompress version 0.29.0.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| adamhathcock sharpcompress | < 0.29.0 | CVE List |
| SharpCompress (NuGet) | before 0.29 | GitHub Advisory Database |
| sharpcompress_project sharpcompress | before 0.29.0 | NVD |
All scores
| GitHub_M | 4.3medium CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N |
| GitHub | 4.3medium CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N |
| GitHub | medium CVSS:4.0 | 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 |
| NVD | 4.0medium CVSS:2.0 | AV:N/AC:L/Au:S/C:N/I:P/A:N |
Classification
What each source says
CVE List
SharpCompress is a fully managed C# library to deal with many compression types and formats. Versions prior to 0.29.0 are vulnerable to partial path traversal. 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, prior to version 0.29.0, it is not enforced that fullDestinationDirectoryPath ends with slash. 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`. Because of the file name and destination directory constraints the arbitrary file creation impact is limited and depends on the use case. This issue is fixed in SharpCompress version 0.29.0.
GitHub Advisory Database
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.
NVD (es)
SharpCompress es una biblioteca de C# totalmente administrada para tratar con muchos tipos y formatos de compresión. Las versiones anteriores a 0.29.0 son vulnerables a un salto de ruta parcial. SharpCompress recrea una jerarquía de directorios bajo destinationDirectory si ExtractFullPath es establecido en true en las opciones. Para evitar una extracción fuera del directorio de destino, es verificado que la ruta destinationFileName comience con fullDestinationDirectoryPath. Sin embargo, antes de la versión 0.29.0, no se exige que fullDestinationDirectoryPath termine con una barra. Si el destinationDirectory no termina en barra como "/home/user/dir" es posible crear un archivo con un nombre que comienza como el directorio de destino un nivel más arriba del directorio, es decir, "/home/user/dir.sh". Debido a las restricciones del nombre del archivo y del directorio de destino, el impacto de la creación arbitraria de archivos es limitado y depende del caso de uso. Este problema es corregido en SharpCompress versión 0.29.0
References
| https://github.com/adamhathcock/sharpcompress/security/advisories/GHSA-jp7f-grcv-6mjf | exploit, third-party-advisory, web | |
| https://github.com/adamhathcock/sharpcompress/pull/614 | patch, third-party-advisory, web | |
| https://github.com/adamhathcock/sharpcompress/releases/tag/0.29.0 | release-notes, third-party-advisory, web | |
| https://nvd.nist.gov/vuln/detail/CVE-2021-39208 | advisory | |
| https://github.com/adamhathcock/sharpcompress/commit/ea5c8dc06314c7a5068e7901c51a625224d2b288 | web | |
| https://github.com/adamhathcock/sharpcompress | package | |
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2021-39208 changed 2024-08-04 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-jp7f-grcv-6mjf changed 2026-07-08 | CC-BY-4.0 |
| NVD | CVE-2021-39208 changed 2026-06-17 | Public domain |