T08 · Insecure Dependencies
Warning
- Location
- scripts/train_lora.py:15
- Finding
- Arbitrary Unpinned Hugging Face Model Repository Loading## Vulnerability Details **File Location**: `scripts/train_lora.py:15,45-48` **Vulnerability Type**: Unpinned and user-selectable remote model dependency **Risk Level**: Medium ### Vulnerable Code ```python p.add_argument("--model_id", default="black-forest-labs/FLUX.1-schnell") ``` ```python pipe = FluxPipeline.from_pretrained( args.model_id, torch_dtype=torch.float32, ) ``` ### Technical Analysis The `--model_id` argument permits the caller to select an arbitrary Hugging Face repository, and `FluxPipeline.from_pretrained()` downloads model artifacts without specifying an immutable `revision` or verifying expected artifact hashes. This creates a supply-chain trust boundary that is not enforced by the script. A repository may change after the skill has been audited, while an attacker who can influence command-line arguments can redirect loading to an attacker-controlled repository. The code does not require an approved repository, immutable commit, or known artifact digest. Loading an untrusted model can cause availability and integrity risks through malformed, poisoned, or unexpectedly large artifacts. Depending on the installed versions and model serialization formats supported by the underlying libraries, unsafe serialized artifacts may also increase the risk of code execution during deserialization. The reviewed code does not explicitly enable remote custom code, so remote-code execution is not established as an unconditional outcome. ### Attack Path 1. An attacker gains influence over the arguments used to invoke `train_lora.py`, or compromises a mutable upstream model repository. 2. The attacker supplies an untrusted repository through `--model_id`, or replaces artifacts in the configured repository's unpinned branch. 3. `FluxPipeline.from_pretrained()` downloads and parses the current repository artifacts. 4. Malformed or oversized artifacts may exhaust memory or storage and terminate training; ...[truncated 900 chars]
- Remediation
- ## Remediation Suggestions 1. Replace unrestricted `--model_id` input with an allowlist of approved repository identifiers. 2. Pin every approved model to an immutable Hugging Face commit: ```python pipe = FluxPipeline.from_pretrained( approved_model_id, revision="FULL_IMMUTABLE_COMMIT_HASH", torch_dtype=torch.float32, use_safetensors=True, trust_remote_code=False, ) ``` 3. Require `safetensors` and reject pickle-based formats wherever supported. 4. Record and verify cryptographic hashes for all expected downloaded artifacts. 5. Validate artifact sizes and available disk and memory capacity before loading. 6. Run model acquisition and parsing in a restricted environment with minimal filesystem permissions, no unnecessary credentials, and network access limited to approved Hugging Face endpoints. 7. Separate model download from training so artifacts can be scanned and approved before use. 8. Lock tested versions of `diffusers`, `transformers`, `peft`, `torch`, and related dependencies in a dependency lock file.
