GHSL-2021-082: Path traversal in SharpCompress - CVE-2021-39208
SharpCompress's WriteEntryToDirectory method did not enforce that the destination directory path ends with a slash, allowing an attacker to create files outside the intended directory by crafting an archive entry whose name begins with the destination directory name. The impact is limited to arbitrary file creation and depends on the use case.
WriteEntryToDirectory used for an archive extraction is vulnerable to partial path traversal.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The code checks that the destination file path starts with the full destination directory path but does not ensure that the directory path ends with a slash, so a file path like '/home/user/dir.sh' is incorrectly considered inside '/home/user/dir'.
Impact
An attacker could create arbitrary files outside the intended extraction directory, but the impact is limited and depends on the use case.
What the attacker needed
DestinationDirectory not slash-terminated; ExtractFullPath set to true; attacker controls archive entry name
The fix
The issue was fixed in version 0.29.0 by enforcing that the destination directory path ends with a slash.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When extracting an archive, the software checks that each file's full path starts with the destination folder path. But if the destination folder path does not end with a slash, a file named like the folder plus extra characters (e.g., 'dir.sh') will still pass the check, even though it is outside the folder. This lets an attacker write files outside the intended directory.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.