Zip Slip Vulnerability
snyk.io
snyk.io
This is a little bit like trying to brand file upload vulnerabilities that put ..'s in the path name in multipart MIME headers. Wait until they find out about NUL bytes!
> Of course, this type of vulnerability has existed before, but recently it has manifested itself in a much larger number of projects and libraries.
They've responsibly notified and helped a number of projects fix this issue[1]. It seems they are being nothing but a good citizen here.
https://nvd.nist.gov/vuln/detail/CVE-2001-1268 (Info-ZIP unzip)
It has, but that so many libraries are still vulnerable by default means it hasn't exactly stuck.
var filePath = path.join(targetFolder, entry.path);
if (filePath.indexOf(targetFolder) != 0) {
return;
}
But if targetFolder="/var/foo", then you can deposit files in "/var/foo.secret" by providing a path "../foo.secret/blub" > zip my.zip ../foo.txt
adding: ../foo.txt (stored 0%)
> unzip -l my.zip
Archive: my.zip
Length Date Time Name
--------- ---------- ----- ----
4 06-05-2018 15:08 ../foo.txt
--------- -------
4 1 file
> unzip my.zip
Archive: my.zip
warning: skipped "../" path component(s) in ../foo.txt
extracting: foo.txt
> zip my.zip outside/foo.txt
adding: outside/foo.txt (stored 0%)
> rm outside/foo.txt
> unzip my.zip
Archive: my.zip
extracting: outside/foo.txt
> cat ../foo.txt
foo
> tar cvf my_tar ../foo.txt
a ../foo.txt
> tar tvf my_tar.tar
-rw-r--r-- 0 benmurphy wheel 4 5 Jun 15:00 ../foo.txt
> tar xvf my_tar.tar
x ../foo.txt: Path contains '..'
tar: Error exit delayed from previous errors.
> ln -s ../ outside
> tar cvf my_tar.tar outside outside/foo.txt
a outside
a outside/foo.txt
> tar tvf my_tar.tar
lrwxr-xr-x 0 benmurphy wheel 0 5 Jun 15:01 outside -> ../
-rw-r--r-- 0 benmurphy wheel 4 5 Jun 15:02 outside/foo.txt
> tar xvf my_tar.tar
x outside
x outside/foo.txt: Cannot extract through symlink outside/foo.txt
tar: Error exit delayed from previous errors.I think you used to be able to do it on an Amiga using the official LHA(?) compression program, due to the Amiga using front slashes as delimiters.
But beyond that, I really wish there was a zip library that let you do all of the nuanced things the format allows. For example, each file in an archive has its own encryption header, so you could create an archive where the first 10 files were clear text but the 11th was encrypted...
edit: ignore comment, misread encryption as compression. Leaving it for posterity.
That seems pretty straightforward given it's necessary to generate "best practice" OCF. Python's stdlib module certainly allows it (ZipFile.write takes an optional compress_type parameter which overrides the one set in the constructor, just "zf.write(fname, compress_type=zipfile.ZIP_STORED)"
This type of screwup goes all the way back to DOS days and beyond with similar stunts being attempted with unix tar.
While we're at it, let's repackage people using terrible passwords as a newly discovered widespread problem.
This situation has never shown signs of improvement.
This is incorrect. Python's tarfile and zipfile (and shutil) modules have no protection against directory traversal.
> If a member filename is an absolute path, a drive/UNC sharepoint and leading (back)slashes will be stripped, e.g.: ///foo/bar becomes foo/bar on Unix, and C:\foo\bar becomes foo\bar on Windows. And all ".." components in a member filename will be removed, e.g.: ../../foo../../ba..r becomes foo../ba..r. On Windows illegal characters (:, <, >, |, ", ?, and *) replaced by underscore (_).
Sure reads like directory traversal mitigation.
While by itself this might be a deliberate design choice, it vows for an easy mistake.
I'm a fan of telling that a function is unsafe (by design) by its name. So `unsafeExtractall` or something like it. That should give a clear warning to investigate unless you know what you're doing.
See https://github.com/python/cpython/blob/3.6/Lib/zipfile.py
You're misreading the warning. It's saying that the module attempts to mitigate the issue (referring back to ZipFile.extract) but pointing out that this may not be entirely reliable, and thus that as the library user you really should inspect/validate archive paths before doing an on-disk extraction.
The tarfile module is still vulnerable: