-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use tarfile filters (PEP 706) when unpacking? #12111
Comments
+1 on ensuring that when unpacking tarfiles, pip never either creates files outside of the target directory, or creates links to files outside of the target directory. I don't believe there is any valid form of sdist that needs the capability to do this (and if there is, I'd support a PEP modifying the sdist spec to make it illegal 🙂) I'd be slightly uncomfortable if we had to make such protection only available in some Python versions, but I could live with it. I have no opinion regarding differences in mode handling. As a Windows user I don't think it affects me, and in general, I don't think we should be trying to preserve mode bits anyway. I suspect someone, somewhere, will have a sdist that expects a particular mode bit to be preserved from source tree, through sdist and wheel, to final install (unless some other part of the chain already breaks this!) Again, I'd be happy to support a PEP that made such expectations illegal, though 😉 This latter is my biggest concern. The sdist format is hugely under-specified, and people could easily be using it in ways we don't know about and wouldn't necessarily sanction. There's a risk that we could end up needing to write a PEP to tighten up the standards (pip's policy is that we implement standard-defined behaviour, so we wouldn't implement significant restrictions unilaterally). |
It's now in the latest security releases of all supported Python versions.
It does: Python's Guess I should mention another potential incompatibility: historically |
Here's the PEP proposal: https://discuss.python.org/t/using-tarfile-data-filter-for-source-distribution-extraction/28928 |
Description
Hello,
This is a continuation of #11464, which unfortunately turned sour.
New security releases of Python add a
filter
argument totarfile.extract
, which allows filtering common security issues.Python 3.12 will raise a
DeprecationWarning
if filter is not specified. I assumepip
will want to avoid the warning.Python 3.14 will change the default to
tarfile.data_filter
.What are your thoughts on how to best handle this? Happy to send a PR after a discussion.
Complicating factors:
pip
has its own elaborate code that's similar todata_filter
, with different details that might need to be preservedpip
reaches into CPython internals (tar._extract_member
), which may avoid both the filtering and the warning.Possible solutions I see:
data_filter
on Pythons that support it. Accept behaviour differences -- AFAIK the biggest one is inmode
handling:data_filter
setsrwx?-??-?
if executable orrw-?--?--
if not (?
=keep info from tarball)pip
uses the OS default, then and adds all 3 executable bits if any are set in the tarballdata_filter
if available to raise exceptions (files/links outside target, device files), use existing mechanism if the filter doesn't failfully_trusted
filter to silence warningsIn the previous issue, @pradyunsg said:
The latter is currently not true: pip's unpacking is vulnerable to symlink attacks. The attached reproducer makes
pip download evil.tar.gz
dump a file in/tmp/poc
, without running arbitrary code.As said before, given pip's security model this isn't a security issue -- AFAIK it could only become one if the function is copied/used as documented elsewhere.
Expected behavior
No response
pip version
main
Python version
3.12
OS
*nix, any
How to Reproduce
mkevil.py
:Output
Code of Conduct
The text was updated successfully, but these errors were encountered: