summaryrefslogtreecommitdiff
path: root/kolla/image
diff options
context:
space:
mode:
authorMichal Nasiadka <mnasiadka@gmail.com>2023-03-16 10:04:47 +0000
committerMichal Nasiadka <mnasiadka@gmail.com>2023-03-20 05:21:29 +0000
commitdac11090b83dee3532cd1da39bf32d69824d45d6 (patch)
tree094660049d2288ffc08d51536ba0172b0a393f34 /kolla/image
parent22518ed6c2660a80b8fdb3bb51d2c0cbe3eb8ef5 (diff)
downloadkolla-dac11090b83dee3532cd1da39bf32d69824d45d6.tar.gz
kolla-dac11090b83dee3532cd1da39bf32d69824d45d6.zip
Test for unsafe files in tarfile.extractall
In addition to that, mark bifrost unbuildable since it's failing on EPEL 9 enablement. Closes-Bug: #1990432 Change-Id: I650fcbc8f773fad8116338f6fb0cf7b4f4f17b33 (cherry picked from commit 3d008b7f5ec2a54d004e8e9370f303ef9dc7858b)
Diffstat (limited to 'kolla/image')
-rw-r--r--kolla/image/tasks.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/kolla/image/tasks.py b/kolla/image/tasks.py
index bfc01dec5..53ae4b705 100644
--- a/kolla/image/tasks.py
+++ b/kolla/image/tasks.py
@@ -264,6 +264,14 @@ class BuildTask(DockerTask):
def builder(self, image):
+ def _test_malicious_tarball(archive, path):
+ tar_file = tarfile.open(archive, 'r|gz')
+ for n in tar_file.getnames():
+ if not os.path.abspath(os.path.join(path, n)).startswith(path):
+ tar_file.close()
+ self.logger.error(f'Unsafe filenames in archive {archive}')
+ raise ArchivingError
+
def make_an_archive(items, arcname, item_child_path=None):
if not item_child_path:
item_child_path = arcname
@@ -277,8 +285,9 @@ class BuildTask(DockerTask):
archives.append(archive_path)
if archives:
for archive in archives:
+ _test_malicious_tarball(archive, items_path)
with tarfile.open(archive, 'r') as archive_tar:
- archive_tar.extractall(path=items_path)
+ archive_tar.extractall(path=items_path) # nosec
else:
try:
os.mkdir(items_path)