Skip to content
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

add exclusion patterns for tarfile-extractall-traversal #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cjenn-aviatrix
Copy link

As per PEP706 the filter arg is used to prevent directory traversal

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

- pattern-not: |
with tarfile.open(...) as $TAR:
...
$TAR.extractall(..., filter=$FILTER, ...)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per https://docs.python.org/3/library/tarfile.html#default-named-filters we may still want to have failing behavior if filter is 'fully_trusted', or None prior to 3.14, but at least this forces it to be explicit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. I think we should still detect cases where filter is set to "fully_trusted", "tar", or None. Since the default will be "data" in Python 3.14 I think that's a reasonable acknowledgment that even "tar" has some security concerns. For example, it allows links to absolute paths or paths outside of the destination.

@GrosQuildu
Copy link
Collaborator

Thanks for the PR!

To sum up, from python3.14 the default filter is data and extraction is safe (except DoS attacks). Is that right?
If so, we may want to either:

  • only detect extractions with explicit fully_trust (targetting 3.14 and more impactful issues)
  • detect the data filters (and filter=None) in addition to fully_trust, maybe lowering the rule's impact (targeting all python versions)

Another question: what happens if both filter and members args are provided:

  • filter=data and members=None
  • filter=fully_trust and members=some_members()

@Cireo
Copy link

Cireo commented Jan 16, 2025

My reading of members is that it simply filters some elements, so while it might be more deliberate than a blind extractall, it is not necessarily more safe. Compare with a single .extract, which is also vulnerable to fully_trusted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants