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.
This commit is contained in:
Dylan M. Taylor
2026-10-21 17:12:54 -04:00
parent ce89625521
commit e25b6ec6e6
+5 -1
View File
@@ -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