Repository navigation
Studio STT: only load safetensors weights for custom dictation models (RCE fix) - #7364
Conversation
The STT sidecar accepts arbitrary Hugging Face owner/model repos for custom dictation models and, when safetensors were absent, downloaded and loaded pytorch_model.bin through WhisperForConditionalGeneration .from_pretrained. PyTorch checkpoints are pickles that execute code during deserialization, and this path does not run the malware gate the normal model loader applies, so an authenticated client on an exposed Studio instance could load a crafted Whisper-looking repo and run code in the backend. Restrict custom STT repos to safetensors: the snapshot selector no longer falls back to pytorch_model.bin(.index.json), the cached-snapshot completeness check ignores pickle weights, and the load forces use_safetensors so a stray cached pickle still cannot execute. The five curated Whisper defaults already ship safetensors only, so this changes nothing for the built-in models.
There was a problem hiding this comment.
💡 Codex Review
unsloth/studio/backend/core/inference/stt_sidecar.py
Lines 379 to 380 in ce1c626
A custom repository can publish model.safetensors.index.json whose weight_map references existing pytorch_model-*.bin shards. This accepts and downloads those shards because only their presence is checked here. use_safetensors=True selects the safetensors index, but Transformers subsequently dispatches each indexed shard according to its own filename, so .bin entries take the PyTorch deserialization path. Require every weight_map value to end in .safetensors (and apply the same validation in _snapshot_is_complete) to keep the intended pickle-free invariant.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A safetensors index (model.safetensors.index.json) is attacker-supplied JSON and can name pytorch_model-*.bin shards in its weight_map. Transformers dispatches shard loading per file by extension, so those .bin shards still load through torch.load (pickle) even with use_safetensors set. Require every weight_map value to end in .safetensors in both the snapshot selector and the completeness check so no pickle shard is downloaded or reused.
|
Good catch on the P1. Fixed in fe30963: a |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Fixes an authenticated remote code execution path introduced with the local STT dictation feature (#7095). The STT sidecar accepts arbitrary Hugging Face
owner/modelrepositories for custom dictation models, and when a repo shipped no safetensors it downloaded and loadedpytorch_model.binthroughWhisperForConditionalGeneration.from_pretrained. PyTorch checkpoints are pickles that execute code during deserialization, and this path never ran the malware gate the normal model loader applies (evaluate_file_securityincore/inference/worker.py, perutils/security/file_security.py). An authenticated client on a network-exposed Studio instance could therefore point dictation at a crafted Whisper-looking repo and run code as the backend user.Fix
Restrict custom STT repositories to safetensors, in three layers so no single check is load-bearing:
_select_snapshot_filesno longer falls back topytorch_model.bin/pytorch_model.bin.index.json; a repo with no safetensors weights fails closed with an actionable error instead of downloading a pickle._snapshot_is_completeignores cached pickle weights, so a previously cached pickle checkpoint is treated as incomplete and re-resolved (then rejected) rather than reused._build_modelpassesuse_safetensors = Truetofrom_pretrained, so even a stray cachedpytorch_model.bincannot be deserialized.Safetensors is pure tensor data and cannot execute code, and
trust_remote_codestays at its defaultFalse, so this closes the load-time RCE surface without depending on a network-time security scan.No behavior change for built-in models
The five curated Whisper defaults (
unsloth/whisper-tiny/-base/-small/-large-v3-turbo/-large-v3) each shipmodel.safetensorsand nopytorch_model.bin, so default dictation is unaffected. Only custom repos that publish pickle weights and no safetensors are now rejected, with a message pointing tosave_pretrained(safe_serialization=True).Tests
test_snapshot_selection_rejects_pickle_only_weights: a repo with onlypytorch_model.binraisesSttModelCompatibilityError.test_pickle_checkpoint_snapshot_is_never_complete: sharded and single-file pickle snapshots read as incomplete; the safetensors equivalent stays complete.test_load_uses_model_hub_cache_without_implicit_download: the weight load assertsuse_safetensors=True.pytorch_model.binis excluded when safetensors are present; those continue to pass.python -m pytest tests/ -k "stt or dictation or whisper or transcribe": 379 passed, 1 skipped.