Skip to content

[BUG] quantize_config.json adapter.path silently downloads and applies attacker-controlled LoRA weights from an arbitrary Hub repository (CWE-20) #3407

Closed

Description

@3em0

Describe the bug

GPTQModel treats the adapter.path value inside quantize_config.json (the manifest data file that ships inside shared model repositories) as a trusted loader argument. When that value names a Hugging Face Hub repository id, Lora.post_init() downloads adapter_config.json and adapter_model.safetensors from that repository via hf_hub_download() (gptqmodel/adapter/remote.py:58-71, called from gptqmodel/adapter/adapter.py:190-205) and Lora.apply() then adds the downloaded matrices (x @ lora_A) @ lora_B onto every forward pass of every adapted quantized linear layer (adapter.py:173). The fetch has no opt-in flag, no allowlist, no revision pinning, no integrity check and no confirmation; the fetched repository is silently persisted into the victim's HF cache. A quantized checkpoint whose manifest points at a second, attacker-controlled and mutable repository therefore makes the victim's process pull and apply attacker-chosen weights at load/inference time — a silent model supply-chain pivot. Data-only: no .py sidecar, no pickle, no trust_remote_code (CWE-20; related CWE-829/CWE-494).

Verified end-to-end at commit 761f76e with a three-arm controlled differential: the positive arm (remote repo id) fetches exactly two remote files and the downloaded weights change the Lora.apply output from [[-1, 4]] to [[3, 8]]; the negative control (byte-identical manifest except adapter.path is a local directory) performs zero network requests; the missing control (nonexistent repo id) reaches the same code sink and receives HTTP 404 — the outbound request happens before any failure is visible to the user.

GPU Info

CPU-only reproduction — no GPU involved in the adapter fetch/apply path, nvidia-smi not applicable (torch 2.14.1+cpu).

Software Info

Operation System: Ubuntu 24.04.3 LTS (WSL2) + Python 3.12.3

$ pip show gptqmodel torch transformers accelerate triton
Name: GPTQModel
Version: 7.5.0 (installed from commit 761f76eadf48140316a869b42ece5cd4f3e252dc)
Name: torch
Version: 2.14.1+cpu
Name: transformers
Version: 5.20.1
Name: accelerate
Version: 1.15.0
Name: triton
Version: not installed (CPU-only venv; gptqmodel logs "Detected no triton")

Also relevant: huggingface_hub 2.2.0, safetensors 0.8.0. Note: requirements.txt omits requests and torchvision, but both are imported at package import time (gptqmodel/utils/image.py, gptqmodel/models/definitions/internvl_chat.py) — I had to install them manually; unrelated to this report but it will bite fresh installs.

If you are reporting an inference bug of a post-quantized model, please post the content of config.json and quantize_config.json.

fixtures/model-positive/quantize_config.json (the attack-carrying file; the adapter block uses exactly the serialization GPTQModel's own Adapter.to_dict() writes, only path is attacker-chosen):

{
  "bits": 4,
  "format": "gptq",
  "group_size": 128,
  "desc_act": false,
  "sym": true,
  "adapter": {
    "name": "lora",
    "path": "attacker/gptqmodel344-positive",
    "rank": null
  }
}

To Reproduce

Attachments: make_poc.py (deterministic fixture generator, values hard-coded), run_victim.py (drives the unmodified real pipeline QuantizeConfig.from_pretrained() → adapter.post_init() → adapter.apply()), fake_hf_hub.py (local logging Hub endpoint standing in for huggingface.co), fixtures/ + SHA256SUMS.txt. The three manifests differ only in the single adapter.path line: attacker/gptqmodel344-positive (remote repo id) / local-lora-adapter (local directory) / attacker/gptqmodel344-missing (nonexistent repo id).

  1. python make_poc.py — generates the three manifests plus the attacker repo content (only adapter_config.json with r: 2 and adapter_model.safetensors; no code files).
  2. python fake_hf_hub.py fixtures/hub-root 8755 > hub_out.txt 2>&1 & then export HF_ENDPOINT=http://127.0.0.1:8755 (on a real engagement the endpoint is huggingface.co and the repo is any repo the attacker controls).
  3. Positive arm, run from inside fixtures/: python ../run_victim.py model-positive — logs Lora(path='attacker/gptqmodel344-positive'), issues HEAD+GET for both remote files (4x HTTP 200), materializes lora_A = [[1,0],[1,1]], lora_B = [[1,2],[0,1]] from the download, prints Lora.apply output = [[3.0, 8.0]], and leaves ~/.cache/huggingface/hub/models--attacker--gptqmodel344-positive behind.
  4. Negative control: reset the endpoint log, wipe the HF cache, run python ../run_victim.py model-negative — resolver takes the local branch (Resolver: Local path: ... twice), output is [[-1.0, 4.0]] (the victim's own adapter math), and wc -l ../hub_server.log prints 0: zero network requests, proving the fetch in step 3 is caused solely by the adapter.path value.
  5. Missing control: wipe the cache, run python ../run_victim.py model-missing — same sink, HEAD .../attacker/gptqmodel344-missing/resolve/main/adapter_config.json returns 404 and LocalEntryNotFoundError propagates out of Lora.post_init().

Expected behavior

quantize_config.json must not be able to pivot the load to a second, mutable remote repository. By default GPTQModel should only resolve adapter files inside the checkpoint's own directory; if remote adapters remain supported, the fetch should require an explicit opt-in (e.g. adapter.allow_remote=True), pin the revision hash, verify a recorded digest before the tensors are applied, and print a loud warning naming the repository being fetched. Instead, any non-URL/non-absolute adapter.path string is passed straight to hf_hub_download() as a repository id and its current content is applied to every forward pass, with only an INFO log line.

Model/Datasets

No external model or dataset download is needed: the PoC is self-contained in the attachments. run_victim.py exercises the real QuantizeConfig.from_pretrained() → Lora.post_init() → Lora.apply() path on tiny locally generated fixtures (rank-2 LoRA for one down_proj module, x = [[1.0, 2.0]]), and the "attacker repository" is served by the attached fake_hf_hub.py at HF_ENDPOINT=http://127.0.0.1:8755 so the whole differential is reproducible offline with deterministic outputs.

Screenshots

link:
http://github.com/3em0/cve_repo/blob/main/2026/GPTQModel_761f76eadf48_Untrusted_Adapter_Path_Remote_LoRA_Weight_Fetch_CWE-20.md

Real-terminal captures of the full three-arm run are attached (Windows Terminal + WSL2 Ubuntu 24.04): 13-positive-remote-fetch.png (4x HTTP 200 to the attacker repo, [[3.0, 8.0]], attacker repo in the victim's HF cache), 14-hub-log-positive.png (endpoint log: HEAD+GET of both files, all 200), 15-negative-local.png (local branch, [[-1.0, 4.0]], no HTTP), 16-hub-log-negative.png (endpoint log: 0 lines), 17-missing-404.png (404 + LocalEntryNotFoundError at the same sink), 18-hub-log-missing.png (endpoint log: the 404 request line); earlier captures show the vulnerable code blocks (remote.py:58-75, adapter.py:186-206, adapter.py:160-173 with md5s matching the pinned commit) and the fixture construction/diff.

Additional context

Why this is a security issue rather than intended behavior: quantize_config.json is exactly the file reviewers and hub users inspect to understand a checkpoint, and a remote adapter.path inverts that guarantee — the audited artifact is not the artifact that runs. Hub repositories are mutable, so the second repository's content can be swapped after the checkpoint has been reviewed, starred or distributed; every subsequent load re-downloads whatever is currently there, silently (INFO log only), and caches it for offline reuse. The repository owner's access logs record the victim's requests even when the fetch fails, as the 404 missing control demonstrates. For adapted layers the attacker decides the additive delta (x @ A) @ B applied at inference — flipping classifications, weakening refusals, or steering downstream agent tool-call parsing — with no code execution involved. Master head 51cc9662 still contains the vulnerable call as of 2026-10-18. Suggested severity: CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:H/A:N = 7.1 (High). Happy to provide the full write-up with the captured evidence and sha256 manifest of all PoC files.

poc.zip

Activity

  1. added
    bug
    on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions