{"id":"CVE-2021-39208","aliases":["CVE-2021-39208","GHSA-jp7f-grcv-6mjf"],"related":[],"kind":"vulnerability","state":"published","title":"WriteEntryToDirectory used for an archive extraction is vulnerable to partial path traversal.","summary":"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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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.","source":"cvelist"},{"lang":"en","text":"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.","format":"markdown","source":"ghsa"},{"lang":"es","text":"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","source":"nvd"}],"published":"2021-09-16T14:35:11.000Z","modified":"2026-07-08T06:29:22.057Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N","score":4.3,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N","score":4.3,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N","score":4.3,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"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","rating":"MEDIUM"},{"scorer":"NVD","scheme":"CVSS:2.0","vector":"AV:N/AC:L/Au:S/C:N/I:P/A:N","score":4,"rating":"MEDIUM"}],"cwes":["CWE-22"],"affected":[{"ranges":[{"version":"< 0.29.0","status":"affected"}],"vendor":"adamhathcock","product":"sharpcompress","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"0.29"}],"ecosystem":"NuGet","package":"SharpCompress","purl":"pkg:nuget/SharpCompress","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"0.29.0"}],"vendor":"sharpcompress_project","product":"sharpcompress","cpe":"cpe:2.3:a:sharpcompress_project:sharpcompress:*:*:*:*:*:*:*:*","source":"nvd"}],"references":[{"url":"https://github.com/adamhathcock/sharpcompress/security/advisories/GHSA-jp7f-grcv-6mjf","tags":["exploit","third-party-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/adamhathcock/sharpcompress/pull/614","tags":["patch","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/adamhathcock/sharpcompress/releases/tag/0.29.0","tags":["release-notes","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2021-39208","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/adamhathcock/sharpcompress/commit/ea5c8dc06314c7a5068e7901c51a625224d2b288","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/adamhathcock/sharpcompress","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2021-39208","url":"https://www.cve.org/CVERecord?id=CVE-2021-39208","licence":"CVE Terms of Use","modified":"2024-08-04T01:58:18.179Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-jp7f-grcv-6mjf","url":"https://github.com/advisories/GHSA-jp7f-grcv-6mjf","licence":"CC-BY-4.0","modified":"2026-07-08T06:29:22.057Z"},{"source":"nvd","name":"NVD","id":"CVE-2021-39208","url":"https://nvd.nist.gov/vuln/detail/CVE-2021-39208","licence":"Public domain","modified":"2026-06-17T04:03:18.913Z"}],"updatedAt":"2026-11-25T22:58:04.007Z","epss":{"score":0.01192,"percentile":0.68856,"date":"2026-12-01T12:00:22.000Z"}}