Skip to content

Instantly share code, notes, and snippets.

@sethmlarson
Last active June 3, 2025 13:38
Show Gist options
  • Save sethmlarson/52398e33eff261329a0180ac1d54f42f to your computer and use it in GitHub Desktop.
Save sethmlarson/52398e33eff261329a0180ac1d54f42f to your computer and use it in GitHub Desktop.
Mitigation for CVE-2025-4517, CVE-2025-4330, CVE-2025-4138, and CVE-2024-12718
import pathlib
# Avoid insecure segments in link names.
# 'tar' is a tarfile open for reading.
for member in tar.getmembers():
if member.linkname and '..' in pathlib.Path(member.linkname).parts:
raise OSError("Tarfile with insecure segment ('..') in linkname")
# Now safe to extract members with the data filter.
tar.extractall(filter="data")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment