Skip to content

Make Codex and Claude Code subscriptions go further: a local model router that gives routine agent work to economical models and keeps your strongest model for the hard parts.

fix(release): support macOS system Python license extraction

johnlanni1bef45ca7aef
diff --git a/scripts/collect-third-party-licenses.py b/scripts/collect-third-party-licenses.py
index ac9c5252..14edca7a 100755
--- a/scripts/collect-third-party-licenses.py
+++ b/scripts/collect-third-party-licenses.py
@@ -264,6 +264,26 @@ def json_sequence(value: str) -> list[dict[str, object]]:
return result
+def extract_regular_tree(bundle: tarfile.TarFile, destination: Path) -> None:
+ """Extract a source archive without relying on version-specific tar filters."""
+ for member in bundle.getmembers():
+ relative = Path(member.name)
+ if relative.is_absolute() or ".." in relative.parts or not relative.parts:
+ raise ValueError("CPA source archive contains an unsafe path")
+ target = destination.joinpath(*relative.parts)
+ if member.isdir():
+ target.mkdir(parents=True, exist_ok=True)
+ continue
+ if not member.isfile():
+ raise ValueError("CPA source archive contains a non-regular entry")
+ source = bundle.extractfile(member)
+ if source is None:
+ raise ValueError("CPA source archive entry is unreadable")
+ target.parent.mkdir(parents=True, exist_ok=True)
+ with target.open("wb") as output:
+ shutil.copyfileobj(source, output)
+
+
def extract_cpa(source_repo: Path, destination: Path) -> tuple[dict[str, object], Path]:
pin_path = REPO / "vendor/cpa/source.json"
pin = json.loads(pin_path.read_text())
@@ -274,7 +294,7 @@ def extract_cpa(source_repo: Path, destination: Path) -> tuple[dict[str, object]
"git", "-C", str(source_repo), "archive", pin["commit"]
])
with tarfile.open(fileobj=io.BytesIO(archive), mode="r:") as bundle:
- bundle.extractall(destination, filter="data")
+ extract_regular_tree(bundle, destination)
run("git", "apply", str(patch), cwd=destination)
return pin, pin_path
diff --git a/scripts/test-third-party-licenses.py b/scripts/test-third-party-licenses.py
index 5b08e2e5..aa912711 100755
--- a/scripts/test-third-party-licenses.py
+++ b/scripts/test-third-party-licenses.py
@@ -1,8 +1,10 @@
#!/usr/bin/env python3
import importlib.util
+import io
import json
from pathlib import Path
+import tarfile
import tempfile
import unittest
@@ -16,6 +18,32 @@ SPEC.loader.exec_module(licenses)
class ThirdPartyLicenseTests(unittest.TestCase):
+ def test_source_archive_extraction_is_portable_and_rejects_traversal(self):
+ with tempfile.TemporaryDirectory() as directory:
+ root = Path(directory)
+ archive = io.BytesIO()
+ with tarfile.open(fileobj=archive, mode="w") as bundle:
+ valid = tarfile.TarInfo("source/LICENSE")
+ valid.size = len(b"license\n")
+ bundle.addfile(valid, io.BytesIO(b"license\n"))
+ archive.seek(0)
+ with tarfile.open(fileobj=archive, mode="r:") as bundle:
+ licenses.extract_regular_tree(bundle, root / "valid")
+ self.assertEqual(
+ (root / "valid/source/LICENSE").read_text(), "license\n"
+ )
+
+ unsafe = io.BytesIO()
+ with tarfile.open(fileobj=unsafe, mode="w") as bundle:
+ traversal = tarfile.TarInfo("../outside")
+ traversal.size = 1
+ bundle.addfile(traversal, io.BytesIO(b"x"))
+ unsafe.seek(0)
+ with tarfile.open(fileobj=unsafe, mode="r:") as bundle, \
+ self.assertRaisesRegex(ValueError, "unsafe path"):
+ licenses.extract_regular_tree(bundle, root / "unsafe")
+ self.assertFalse((root / "outside").exists())
+
def test_license_file_discovery_is_bounded_and_includes_unlicense(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)