From e25b6ec6e60d22dcd9073542d10aa5a0d3e26ce1 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 21 Oct 2026 17:12:54 -0400 Subject: [PATCH] security: validate CLI paths/args in dev tools (SonarCloud S2083/S8707/S8705/S7044) Resolve and validate command-line path arguments before use, enforce HTTPS at download sinks, and confirm path containment. Hardens local codegen/fetch tools against path-traversal and command-argument-injection findings. --- scripts/fetch-pdf-test-fonts.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/fetch-pdf-test-fonts.py b/scripts/fetch-pdf-test-fonts.py index 821a5e748..99ce39469 100644 --- a/scripts/fetch-pdf-test-fonts.py +++ b/scripts/fetch-pdf-test-fonts.py @@ -11,6 +11,8 @@ import urllib.request def fetch(url): + if not url.startswith("https://"): + raise ValueError("refusing to fetch a non-HTTPS URL") for attempt in range(3): try: with urllib.request.urlopen(url, timeout=60) as response: @@ -42,7 +44,9 @@ def main(): name, url, digest = fixture["name"], fixture["source"], fixture["sha256"] if Path(name).name != name or name in ("", ".", "..") or not url.startswith("https://"): raise ValueError("invalid fixture name or source") - path = destination / name + path = (destination / name).resolve() + if path.parent != destination: + raise ValueError(f"fixture path escapes destination: {name}") if path.is_file() and hashlib.sha256(path.read_bytes()).hexdigest() == digest: print(f"Verified {name}") continue