A tar archive is extracted without a filter, so its members can write outside the target directory
What it finds
Members of a tar archive may have names such as ../../etc/cron.d/x or be links to anywhere, and extractall writes them where they point unless a filter says otherwise. filter="data", available since Python 3.12 and in security updates of older versions, refuses such members. Reported are extractall and extract calls without filter on names that tarfile.open was assigned to, directly or by with, and shutil.unpack_archive without filter.
From the rule's source, tar_extract_without_filter.rs.
import shutilimport tarfile def unpack(path, target): with tarfile.open(path) as archive: archive.extractall(target)tx0 reports: this archive is extracted without filter tar = tarfile.open(path) tar.extractall(target, filter="data") tar.extract("a", target)tx0 reports: this archive is extracted without filter shutil.unpack_archive(path, target)tx0 reports: this archive is extracted without filter zipped.extractall(target) Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:tar-extract-without-filter" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:tar-extract-without-filter] reason="..."tx0 explain tx0/python:tar-extract-without-filter shows the same in the terminal. Found a false positive? Report it.