Skip to content

Implement PEP 706 – Filter for tarfile.extractall #102950

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

Closed
1 task done
encukou opened this issue Mar 23, 2023 · 14 comments
Closed
1 task done

Implement PEP 706 – Filter for tarfile.extractall #102950

encukou opened this issue Mar 23, 2023 · 14 comments
Assignees
Labels
type-feature A feature request or enhancement type-security A security issue

Comments

@encukou encukou added the type-feature A feature request or enhancement label Mar 23, 2023
encukou added a commit to encukou/cpython that referenced this issue Apr 25, 2023
Also remove expilcit `type=tarfile.DIRTYPE`, the slash at the end
is enough.
encukou added a commit that referenced this issue Apr 25, 2023
… sticky bit (GH-103831)

Also remove expilcit `type=tarfile.DIRTYPE`, the slash at the end is
enough.
encukou added a commit to encukou/cpython that referenced this issue Apr 25, 2023
…et the sticky bit (pythonGH-103831)

Also remove expilcit `type=tarfile.DIRTYPE`, the slash at the end is
enough.

Backport of c8c3956
encukou added a commit that referenced this issue Apr 28, 2023
…H-102953) (GH-103832)

See [Backporting & Forward Compatibility in PEP 706](https://peps.python.org/pep-0706/#backporting-forward-compatibility).

- Backport b52ad18
- Backport c8c3956
- Remove the DeprecationWarning
- Adjust docs
- Remove new `__all__` entries
@gpshead gpshead added the type-security A security issue label May 2, 2023
@mcepl
Copy link
Contributor

mcepl commented May 3, 2023

And I really think #73974 (CVE-2007-4559) should be mentioned somewhere in this PR.

mcepl pushed a commit to openSUSE-Python/cpython that referenced this issue May 3, 2023
…et the sticky bit (pythonGH-103831)

Also remove expilcit `type=tarfile.DIRTYPE`, the slash at the end is
enough.

Backport of c8c3956
@encukou
Copy link
Member Author

encukou commented May 3, 2023

Well, the PR was open for a month, but now it's closed. Feel free to suggest an update to the docs.
Note that Python 3.12 doesn't “fix” CVE-2007-4559 (depending on how you define “fix”).

encukou added a commit that referenced this issue May 10, 2023
…H-102953) (GH-104128)

- Backport b52ad18
- Backport c8c3956
- Remove the DeprecationWarning
- Adjust docs
- Remove new `__all__` entries

Co-authored-by: Petr Viktorin <[email protected]>
encukou added a commit to encukou/cpython that referenced this issue May 11, 2023
…et the sticky bit (pythonGH-103831)

Also remove expilcit `type=tarfile.DIRTYPE`, the slash at the end is
enough.

Backport of c8c3956
encukou added a commit to encukou/cpython that referenced this issue May 11, 2023
…et the sticky bit (pythonGH-103831)

Also remove expilcit `type=tarfile.DIRTYPE`, the slash at the end is
enough.

Backport of c8c3956
encukou added a commit to encukou/cpython that referenced this issue May 16, 2023
…et the sticky bit (pythonGH-103831)

Also remove expilcit `type=tarfile.DIRTYPE`, the slash at the end is
enough.

Backport of c8c3956
@ned-deily
Copy link
Member

Per the discussion in #104583, we have decided that it is not feasible to safely merge the proposed 3.7 version of this fix prior to 3.7's imminent end-of-life. Third-party distributors of cPython who plan to provide support for 3.7 past its official end-of-life are free, of course, to choose to merge or adapt the PR for their users.

@mcepl
Copy link
Contributor

mcepl commented May 30, 2023

Well, the PR was open for a month, but now it's closed. Feel free to suggest an update to the docs. Note that Python 3.12 doesn't “fix” CVE-2007-4559 (depending on how you define “fix”).

I would say “deals with”, which should cover everything. ;)

@ben-spiller
Copy link

Hi, I just upgraded from 3.11 to Python 3.12 and this PR is producing DeprecationWarnings (ok) that can't be easily avoided (not ok!) while calling shutil.unpack_archive(): Python 3.14 will, by default, filter extracted tar archives and reject files or modify their metadata. Use the filter argument to control this behavior.

While the idea of a deprecation warning for tarfile with filter=None is clearly reasonable, the impact of this on shutil.unpack_archive() is really unfortunate and could use more consideration. The whole point of unpack_archive is to provide a way to unpack an archive without the caller having to special-case different archive formats. It's now impossible to use unpack_archive for different formats in Python 3.12 without either

a) hitting the new v3.12 deprecation warning for not specifying filter='...' (imho it's not ok to ignore warnings!), or

b) special-casing how caller invokes unpack_archive() for different archive types i.e. passing filter='data' if archive contains .tar/tgz/txz/etc but filter=None if archive is a zipfile. Determining which case is not trivial for the caller of unpack_archive(), and should be taken care of by the library.

Both of those options are pretty gross and make this change very hard to adapt to without gross hacks or disabling deprecation warnings (not a great practice).

Some possible solutions:

  • provide some value of filter= that can be passed to both tarfile and other archive formats that don't yet/don't need to support tar-style safe extraction (as PEP-0706 states, "ZipFile.extract’s defaults are already similar to what a 'data' filter would do")
  • remove the deprecation warning asap until a future release when there's time to do the above or plan another solution. (nb: this deprecation is not documented in the "Important deprecations, removals or restrictions" section of release notes so removing it in a patch would seem reasonable)
  • make unpack_archive pass the filter= flag down to tarfile but not to other archive classes

Right now it's a breaking change and I can't see any nice way to work around it.

stratakis pushed a commit to stratakis/cpython that referenced this issue Feb 27, 2024
Implement PEP 706 – Filter for tarfile.extractall

Upstream issue: python#102950

Tracker bug: https://bugzilla.redhat.com/show_bug.cgi?id=263261
hroncok pushed a commit to fedora-python/cpython that referenced this issue Mar 7, 2024
Add API for allowing checks on the content of tar files, allowing callers to mitigate
directory traversal (CVE-2007-4559) and related issues.

Python 3.12 will warn if this API is not used.
Python 3.14 will fail if it's not used.

Backport from python#102950

Change document: https://peps.python.org/pep-0706/
stratakis pushed a commit to stratakis/cpython that referenced this issue Mar 11, 2024
Add API for allowing checks on the content of tar files, allowing callers to mitigate
directory traversal (CVE-2007-4559) and related issues.

Python 3.12 will warn if this API is not used.
Python 3.14 will fail if it's not used.

Backport from python#102950

Change document: https://peps.python.org/pep-0706/
stratakis pushed a commit to stratakis/cpython that referenced this issue Mar 11, 2024
Add API for allowing checks on the content of tar files, allowing callers to mitigate
directory traversal (CVE-2007-4559) and related issues.

Python 3.12 will warn if this API is not used.
Python 3.14 will fail if it's not used.

Backport from python#102950

Change document: https://peps.python.org/pep-0706/
stratakis pushed a commit to stratakis/cpython that referenced this issue Mar 20, 2024
Add API for allowing checks on the content of tar files, allowing callers to mitigate
directory traversal (CVE-2007-4559) and related issues.

Python 3.12 will warn if this API is not used.
Python 3.14 will fail if it's not used.

Backport from python#102950

Change document: https://peps.python.org/pep-0706/
stratakis pushed a commit to stratakis/cpython that referenced this issue Mar 20, 2024
Add API for allowing checks on the content of tar files, allowing callers to mitigate
directory traversal (CVE-2007-4559) and related issues.

Python 3.12 will warn if this API is not used.
Python 3.14 will fail if it's not used.

Backport from python#102950

Change document: https://peps.python.org/pep-0706/
stratakis pushed a commit to stratakis/cpython that referenced this issue Mar 20, 2024
Add API for allowing checks on the content of tar files, allowing callers to mitigate
directory traversal (CVE-2007-4559) and related issues.

Python 3.12 will warn if this API is not used.
Python 3.14 will fail if it's not used.

Backport from python#102950

Change document: https://peps.python.org/pep-0706/
stratakis pushed a commit to stratakis/cpython that referenced this issue Mar 20, 2024
Add API for allowing checks on the content of tar files, allowing callers to mitigate
directory traversal (CVE-2007-4559) and related issues.

Python 3.12 will warn if this API is not used.
Python 3.14 will fail if it's not used.

Backport from python#102950

Change document: https://peps.python.org/pep-0706/
stratakis pushed a commit to stratakis/cpython that referenced this issue Mar 25, 2024
Add API for allowing checks on the content of tar files, allowing callers to mitigate
directory traversal (CVE-2007-4559) and related issues.

Python 3.12 will warn if this API is not used.
Python 3.14 will fail if it's not used.

Backport from python#102950

Change document: https://peps.python.org/pep-0706/
hroncok pushed a commit to fedora-python/cpython that referenced this issue Mar 26, 2024
Add API for allowing checks on the content of tar files, allowing callers to mitigate
directory traversal (CVE-2007-4559) and related issues.

Python 3.12 will warn if this API is not used.
Python 3.14 will fail if it's not used.

Backport from python#102950

Change document: https://peps.python.org/pep-0706/
mcepl pushed a commit to openSUSE-Python/cpython that referenced this issue Mar 28, 2024
…et the sticky bit (pythonGH-103831)

Also remove expilcit `type=tarfile.DIRTYPE`, the slash at the end is
enough.

Backport of c8c3956
mcepl pushed a commit to openSUSE-Python/cpython that referenced this issue Apr 2, 2024
Add API for allowing checks on the content of tar files, allowing callers to mitigate
directory traversal (CVE-2007-4559) and related issues.

Python 3.12 will warn if this API is not used.
Python 3.14 will fail if it's not used.

Backport from python#102950

Change document: https://peps.python.org/pep-0706/
icanhasmath pushed a commit to ActiveState/cpython that referenced this issue Jul 19, 2024
hrnciar pushed a commit to fedora-python/cpython that referenced this issue Apr 23, 2025
Add API for allowing checks on the content of tar files, allowing callers to mitigate
directory traversal (CVE-2007-4559) and related issues.

Python 3.12 will warn if this API is not used.
Python 3.14 will fail if it's not used.

Backport from python#102950

Change document: https://peps.python.org/pep-0706/
rickprice added a commit to ActiveState/cpython that referenced this issue May 7, 2025
rickprice added a commit to ActiveState/cpython that referenced this issue May 9, 2025
rickprice added a commit to ActiveState/cpython that referenced this issue May 10, 2025
rickprice added a commit to ActiveState/cpython that referenced this issue May 10, 2025
rickprice added a commit to ActiveState/cpython that referenced this issue May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement type-security A security issue
Projects
None yet
Development

No branches or pull requests

5 participants