Coordinated Disclosure Timeline
- 2021-09-03: Report sent to maintainer.
- 2021-09-04: Maintainer acknowledges.
- 2021-09-06: Proof of Concept sent.
- 2021-09-12: 0.29.0 version with the fix released.
- 2021-09-12: Security advisory published.
Summary
WriteEntryToDirectory
used for an archive extraction is vulnerable to partial path traversal.
Product
Tested Version
0.28.3
Details
Issue: Extraction directory path is not enforced to be slash terminated
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);
...
destinationFileName = Path.GetFullPath(destinationFileName);
if (!destinationFileName.StartsWith(fullDestinationDirectoryPath, StringComparison.Ordinal))
{
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 that begins with the destination 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.
CVE
- CVE-2021-39208
Credit
This issue was discovered and reported by GHSL team member @JarLob (Jaroslav Lobačevski).
Contact
You can contact the GHSL team at securitylab@github.com
, please include a reference to GHSL-2021-082
in any communication regarding this issue.