@@ -40,9 +40,12 @@ Some facts and figures:
4040 Archives are extracted using a :ref: `filter <tarfile-extraction-filter >`,
4141 which makes it possible to either limit surprising/dangerous features,
4242 or to acknowledge that they are expected and the archive is fully trusted.
43- By default, archives are fully trusted, but this default is deprecated
44- and slated to change in Python 3.14.
4543
44+ .. versionchanged :: 3.14
45+ Set the default extraction filter to :func: `data <data_filter> `,
46+ which disallows some dangerous features such as links to absolute paths
47+ or paths outside of the destination. Previously, the filter strategy
48+ was equivalent to :func: `fully_trusted <fully_trusted_filter> `.
4649
4750.. function :: open(name=None, mode='r', fileobj=None, bufsize=10240, **kwargs)
4851
@@ -495,18 +498,18 @@ be finalized; only the internally used file object will be closed. See the
495498 The *filter * argument specifies how ``members `` are modified or rejected
496499 before extraction.
497500 See :ref: `tarfile-extraction-filter ` for details.
498- It is recommended to set this explicitly depending on which *tar * features
499- you need to support.
501+ It is recommended to set this explicitly only if specific *tar * features
502+ are required, or as ``filter='data' `` to support Python versions with a less
503+ secure default (3.13 and lower).
500504
501505 .. warning ::
502506
503507 Never extract archives from untrusted sources without prior inspection.
504- It is possible that files are created outside of *path *, e.g. members
505- that have absolute filenames starting with ``"/" `` or filenames with two
506- dots ``".." ``.
507508
508- Set ``filter='data' `` to prevent the most dangerous security issues,
509- and read the :ref: `tarfile-extraction-filter ` section for details.
509+ Since Python 3.14, the default (:func: `data <data_filter> `) will prevent
510+ the most dangerous security issues.
511+ However, it will not prevent *all * unintended or insecure behavior.
512+ Read the :ref: `tarfile-extraction-filter ` section for details.
510513
511514 .. versionchanged :: 3.5
512515 Added the *numeric_owner * parameter.
@@ -517,6 +520,9 @@ be finalized; only the internally used file object will be closed. See the
517520 .. versionchanged :: 3.12
518521 Added the *filter * parameter.
519522
523+ .. versionchanged :: 3.14
524+ The *filter * parameter now defaults to ``'data' ``.
525+
520526
521527.. method :: TarFile.extract(member, path="", set_attrs=True, *, numeric_owner=False, filter=None)
522528
@@ -536,10 +542,8 @@ be finalized; only the internally used file object will be closed. See the
536542
537543 .. warning ::
538544
539- See the warning for :meth: `extractall `.
540-
541- Set ``filter='data' `` to prevent the most dangerous security issues,
542- and read the :ref: `tarfile-extraction-filter ` section for details.
545+ Never extract archives from untrusted sources without prior inspection.
546+ See the warning for :meth: `extractall ` for details.
543547
544548 .. versionchanged :: 3.2
545549 Added the *set_attrs * parameter.
@@ -602,14 +606,8 @@ be finalized; only the internally used file object will be closed. See the
602606 String names are not allowed for this attribute, unlike the *filter *
603607 argument to :meth: `~TarFile.extract `.
604608
605- If ``extraction_filter `` is ``None `` (the default),
606- calling an extraction method without a *filter * argument will raise a
607- ``DeprecationWarning ``,
608- and fall back to the :func: `fully_trusted <fully_trusted_filter> ` filter,
609- whose dangerous behavior matches previous versions of Python.
610-
611- In Python 3.14+, leaving ``extraction_filter=None `` will cause
612- extraction methods to use the :func: `data <data_filter> ` filter by default.
609+ If ``extraction_filter `` is ``None `` (the default), extraction methods
610+ will use the :func: `data <data_filter> ` filter by default.
613611
614612 The attribute may be set on instances or overridden in subclasses.
615613 It also is possible to set it on the ``TarFile `` class itself to set a
@@ -619,6 +617,14 @@ be finalized; only the internally used file object will be closed. See the
619617 To set a global default this way, a filter function needs to be wrapped in
620618 :func: `staticmethod() ` to prevent injection of a ``self `` argument.
621619
620+ .. versionchanged :: 3.14
621+
622+ The default filter is set to :func: `data <data_filter> `,
623+ which disallows some dangerous features such as links to absolute paths
624+ or paths outside of the destination.
625+ Previously, the default was equivalent to
626+ :func: `fully_trusted <fully_trusted_filter> `.
627+
622628.. method :: TarFile.add(name, arcname=None, recursive=True, *, filter=None)
623629
624630 Add the file *name * to the archive. *name * may be any type of file
@@ -969,6 +975,12 @@ In most cases, the full functionality is not needed.
969975Therefore, *tarfile * supports extraction filters: a mechanism to limit
970976functionality, and thus mitigate some of the security issues.
971977
978+ .. warning ::
979+
980+ None of the available filters blocks *all * dangerous archive features.
981+ Never extract archives from untrusted sources without prior inspection.
982+ See also :ref: `tarfile-further-verification `.
983+
972984.. seealso ::
973985
974986 :pep: `706 `
@@ -992,12 +1004,13 @@ can be:
9921004
9931005* ``None `` (default): Use :attr: `TarFile.extraction_filter `.
9941006
995- If that is also ``None `` (the default), raise a `` DeprecationWarning ``,
996- and fall back to the `` 'fully_trusted' `` filter, whose dangerous behavior
997- matches previous versions of Python.
1007+ If that is also ``None `` (the default), the `` 'data' `` filter will be used.
1008+
1009+ .. versionchanged :: 3.14
9981010
999- In Python 3.14, the ``'data' `` filter will become the default instead.
1000- It's possible to switch earlier; see :attr: `TarFile.extraction_filter `.
1011+ The default filter is set to :func: `data <data_filter> `.
1012+ Previously, the default was equivalent to
1013+ :func: `fully_trusted <fully_trusted_filter> `.
10011014
10021015* A callable which will be called for each extracted member with a
10031016 :ref: `TarInfo <tarinfo-objects >` describing the member and the destination
@@ -1080,6 +1093,9 @@ reused in custom filters:
10801093
10811094 Return the modified ``TarInfo `` member.
10821095
1096+ Note that this filter does not block *all * dangerous archive features.
1097+ See :ref: `tarfile-further-verification ` for details.
1098+
10831099
10841100.. _tarfile-extraction-refuse :
10851101
@@ -1093,6 +1109,8 @@ With ``errorlevel=0`` the error will be logged and the member will be skipped,
10931109but extraction will continue.
10941110
10951111
1112+ .. _tarfile-further-verification :
1113+
10961114Hints for further verification
10971115~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10981116
@@ -1110,9 +1128,10 @@ Here is an incomplete list of things to consider:
11101128 disk, memory and CPU usage.
11111129* Check filenames against an allow-list of characters
11121130 (to filter out control characters, confusables, foreign path separators,
1113- etc. ).
1131+ and so on ).
11141132* Check that filenames have expected extensions (discouraging files that
1115- execute when you “click on them”, or extension-less files like Windows special device names).
1133+ execute when you “click on them”, or extension-less files like Windows
1134+ special device names).
11161135* Limit the number of extracted files, total size of extracted data,
11171136 filename length (including symlink length), and size of individual files.
11181137* Check for files that would be shadowed on case-insensitive filesystems.
0 commit comments