mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 19:13:28 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user