Skip to content

Commit cd17c77

Browse files
Fix insecure Hugging Face model download by pinning revision
Co-authored-by: adamvangrover <200125393+adamvangrover@users.noreply.github.com>
1 parent f8818ef commit cd17c77

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

.jules/sentinel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,8 @@
230230
**Vulnerability:** `WorkspaceManager._run_hook` executed `subprocess.run(['bash', '-lc', script])`. If an attacker supplies a script string starting with `-` (like `-i`), `bash` interprets it as an option instead of a script payload, leading to an unexpected execution behavior or potential bypasses.
231231
**Learning:** Even when passing a script directly to an interpreter like `bash -c`, untrusted scripts that start with a hyphen can cause argument injection.
232232
**Prevention:** Always use the end-of-options separator `--` before the untrusted payload when evaluating it via interpreters like bash (e.g., `['bash', '-lc', '--', script]`).
233+
234+
## 2026-05-24 - Unsafe Hugging Face Hub download without revision pinning
235+
**Vulnerability:** Hugging Face model downloads via `from_pretrained()` without a `revision` parameter are vulnerable to supply chain attacks, as the default branch can be updated with malicious weights.
236+
**Learning:** Bandit rule B615 explicitly requires pinning the `revision` parameter to a specific cryptographic commit hash (not a branch tag like "main") for secure model fetching.
237+
**Prevention:** Always pin Hugging Face dependencies to a verifiable commit hash (e.g., `revision="27d67f1b5f57dc0953326b2601d68371d40ea8da"`) when calling `from_pretrained()`.

core/ppo_trainer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ def your_data_collator(data):
8282

8383

8484
# 1. Configuration for the Harness
85+
MODEL_NAME = "mistralai/Mistral-7B-v0.1"
86+
MODEL_REVISION = "27d67f1b5f57dc0953326b2601d68371d40ea8da"
8587
config = PPOConfig(
86-
model_name="mistralai/Mistral-7B-v0.1",
88+
model_name=MODEL_NAME,
8789
learning_rate=1.41e-5,
8890
batch_size=16,
8991
mini_batch_size=4,
@@ -103,6 +105,7 @@ def your_data_collator(data):
103105
# 3. Load the Actor and Critic (Value Head) together
104106
model = AutoModelForCausalLMWithValueHead.from_pretrained(
105107
config.model_name,
108+
revision=MODEL_REVISION,
106109
peft_config=lora_config,
107110
device_map="auto",
108111
load_in_8bit=True, # Requires bitsandbytes
@@ -111,7 +114,7 @@ def your_data_collator(data):
111114
# The Reference model is automatically handled by trl
112115
# (it disables the LoRA adapters to get reference probabilities)
113116

114-
tokenizer = AutoTokenizer.from_pretrained(config.model_name)
117+
tokenizer = AutoTokenizer.from_pretrained(config.model_name, revision=MODEL_REVISION)
115118
tokenizer.pad_token = tokenizer.eos_token
116119

117120
# 4. Initialize the PPO Trainer

0 commit comments

Comments
 (0)