[Python-Dev] tarfile and directory traversal vulnerability
jmatejek at suse.cz
Fri Aug 24 19:36:41 CEST 2007
-----BEGIN PGP SIGNED MESSAGE-----
once upon a time there was a known vulnerability in tar (CVE-2001-1267,
), and while tar is now long fixed, python's tarfile module is
The vulnerability goes basically like this: If you tar a file named
"../../../../../etc/passwd" and then make the admin untar it,
/etc/passwd gets overwritten.
Another variety of this bug is a symlink one: if tar contains files like:
./aaaa-directory -> /etc
then the "aaaa-directory" symlink would be created first and /etc/passwd
will be overwritten once again.
I was wondering how to fix it.
The symlink problem obviously applies only to extractall() method and is
easily fixed by delaying external (or possibly all) symlink creation,
similar to how directory attributes are delayed now.
I've attached a draft of the patch, if you like it, i'll polish it.
The traversal problem is harder, and it applies to extract() method as well.
For extractall() alone, i would use something like:
warnings.warn("non-local file skipped: %s" % tarinfo.name,
For extract(), i am not sure. Maybe it should throw exception when it
encounters such file, and have a special option to extract such files
anyway. Or maybe it should be left alone altogether.
Any suggestions are welcome.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 1127 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-dev/attachments/20070824/5605f4ef/attachment.bin
More information about the Python-Dev