Skip to content

Commit 8f580fa

Browse files
authored
Add hardening measures on untar (#49)
This adds hardening measures while untaring archives fetched over the network (including FreeBSD tarballs and iocage plugins), as implemented by TrueNAS, see: truenas/iocage#358 This reduces the impact of intentionally malicious or accidentally broken archives. Please note that users are still advised to only fetch from trusted sources and make use of TLS to prevent MITM attacks.
1 parent e786c01 commit 8f580fa

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

iocage_lib/ioc_fetch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
from iocage_lib.pools import Pool
4848
from iocage_lib.dataset import Dataset
4949

50+
# deliberately crash if tarfile doesn't have required filter
51+
tarfile.tar_filter
52+
5053

5154
class IOCFetch:
5255

@@ -817,7 +820,7 @@ def fetch_extract(self, f):
817820
# removing them first.
818821
member = self.__fetch_extract_remove__(f)
819822
member = self.__fetch_check_members__(member)
820-
f.extractall(dest, members=member)
823+
f.extractall(dest, members=member, filter='tar')
821824

822825
def fetch_update(self, cli=False, uuid=None):
823826
"""This calls 'freebsd-update' to update the fetched RELEASE."""

iocage_lib/ioc_plugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
GIT_LOCK = threading.Lock()
6262
RE_PLUGIN_VERSION = re.compile(r'"path":"([/\.\+,\d\w-]*)\.txz"')
6363

64+
# deliberately crash if tarfile doesn't have required filter
65+
tarfile.tar_filter
66+
6467

6568
class IOCPlugin(object):
6669

@@ -157,7 +160,7 @@ def download_parse_packagesite(packagesite_url):
157160
shutil.copyfileobj(r.raw, f)
158161

159162
with tarfile.open(packagesite_txz_path) as p_file:
160-
p_file.extractall(path=tmpdir)
163+
p_file.extractall(path=tmpdir, filter='data')
161164

162165
packagesite_path = os.path.join(tmpdir, 'packagesite.yaml')
163166
if not os.path.exists(packagesite_path):

0 commit comments

Comments
 (0)