T08 · Insecure Dependencies
- Location
scripts/transcribe_video.py:17- Finding
Downloaded Whisper model is not cryptographically authenticated
- Content
View full analysis
{MODEL_BIN}", flush=True) import urllib.request part = MODEL_BIN + ".part" req = urllib.request.Request(MODEL_URL) with urllib.request.urlopen(req, timeout=900) as r, open(part, "wb") as f: while True: chunk = r.read(1 << 20) if not chunk: break f.write(chunk) os.rename(part, MODEL_BIN) got = os.path.getsize(MODEL_BIN) if got != MODEL_EXPECTED_BYTES: print(f"[model] WARNING: {got} != expected {MODEL_EXPECTED_BYTES}", flush=True) print(f"[model] ready ({got} bytes)", flush=True) ``` The resulting artifact is subsequently loaded at line 113: ```python model = WhisperModel(MODEL_DIR, device="cpu", compute_type="int8") ``` ### Technical Analysis The script treats an exact file length as proof that the model is intact. File size does not authenticate content: an attacker who can modify the remote artifact or its upstream distribution can produce a different file with the same length. The post-download validation is weaker still. If the downloaded file has an unexpected size, the s ...[truncated 1761 chars]- Remediation
View remediation
" def sha256_file(path): digest = hashlib.sha256() with open(path, "rb") as source: for chunk in iter(lambda: source.read(1024 * 1024), b""): digest.update(chunk) return digest.hexdigest() if sha256_file(part) != MODEL_SHA256: os.remove(part) raise RuntimeError("Downloaded model failed SHA-256 verification") os.replace(part, MODEL_BIN) ``` ]]>
