Skip to content

Commit

Permalink
Merge pull request #7295 from pmisik/PEP706_Filter4Tarfile
Browse files Browse the repository at this point in the history
Improve security of tarfile extraction addressed by PEP 706
  • Loading branch information
p12tic committed Dec 20, 2023
2 parents f0d8e79 + 180a490 commit 7b99502
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion master/buildbot/process/remotetransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ def remote_unpack(self):

# Unpack archive and clean up after self
with tarfile.open(name=self.tarname, mode=mode) as archive:
archive.extractall(path=self.destroot)
if hasattr(tarfile, 'data_filter'):
archive.extractall(path=self.destroot, filter='data')
else:
archive.extractall(path=self.destroot)
os.remove(self.tarname)


Expand Down
5 changes: 4 additions & 1 deletion master/buildbot/test/integration/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def setUpUpgradeTest(self):
with tarfile.open(tarball) as tf:
prefixes = set()
for inf in tf:
tf.extract(inf)
if hasattr(tarfile, 'data_filter'):
tf.extract(inf, filter='data')
else:
tf.extract(inf)
prefixes.add(inf.name.split('/', 1)[0])

# get the top-level dir from the tarball
Expand Down
1 change: 1 addition & 0 deletions newsfragments/tarfile-pep706.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved security of tarfile extraction to help avoid CVE-2007-4559. See more details in https://peps.python.org/pep-0706/. Buildbot uses filter='data' now. (:issue:`7294`)

0 comments on commit 7b99502

Please sign in to comment.