Skip to content

fix: block untrusted remote LoRA adapters - #3409

Merged
Qubitium merged 4 commits into
ModelCloud:mainfrom
mikemikimike:fix/3407-block-untrusted-remote-adapters
Oct 22, 2026
Merged

Qubitium merged 4 commits into
ModelCloud:mainfrom
mikemikimike:fix/3407-block-untrusted-remote-adapters

Conversation

@mikemikimike

@mikemikimike mikemikimike commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Keep adapter paths loaded from checkpoint metadata inside checkpoint storage; metadata cannot authorize Hub downloads.
  • Require explicit opt-in, an immutable Hub commit, and a SHA-256 digest for remote adapters supplied by callers.
  • Verify adapter weights before loading them with safetensors and include the pin in the adapter cache key.

What Changed

  • Enforce checkpoint provenance at Lora.post_init, including direct QuantizeConfig.from_pretrained() usage. Reject absolute/UNC paths before probing them, directory symlinks, and external adapter-file links; preserve standard same-repository Hugging Face snapshot-to-blob links.
  • Validate complete revision/digest pairs before config I/O; reject remote-to-local fallback and verify supplied digests on local resolution too.
  • Resolve pinned blob URLs' config and weights from the same containing folder, including nested folders and repositories named blob.
  • Normalize explicit dictionary and PathLike adapters, clear stale authorization when reconfiguring, canonicalize local cache keys, and validate rank on cache hits. Preserve relative manifest paths when serializing adapters and allow optional null tensor fields while rejecting non-tensor payloads.
  • Document the explicit remote opt-in and checkpoint-storage restrictions; add fast regression tests.

Tests

  • Unit tests have been executed and passed.
  • Added new simple/fast regression tests.
PYTHONPATH=. python -m pytest tests/test_adapter_remote_security.py tests/test_adapter_config.py tests/test_auto_adapter_generate.py tests/test_quantize_config_offload_tempdir.py -x -q
# 57 passed in 5.86s (Python 3.12.13)

python -m ruff check gptqmodel/adapter/remote.py gptqmodel/adapter/adapter.py gptqmodel/models/loader.py gptqmodel/quantization/config.py tests/test_adapter_remote_security.py
# All checks passed

python -m compileall -q gptqmodel/adapter gptqmodel/quantization/config.py tests/test_adapter_remote_security.py
git diff --check
# Passed

Review Requirements

  • Reviewed this PR.
  • Checked existing project structure, APIs, and conventions.
  • Used targeted mocked Hub downloads to verify rejection and pin forwarding without network access.
  • Kept the changes focused on adapter loading, configuration provenance, documentation, and regression tests.
  • Checked local loading, HF cache compatibility, serialization, and adapter generation regressions.

Kernel Accuracy Requirements

Not applicable: no quantization arithmetic, packer, or inference-kernel changes.

Notes

  • Full GPU/model LoRA inference was not rerun in this review; this VM has no CUDA/ROCm device. The small adapter-loading tests execute real safetensors reads and tensor application locally.
  • A broader Ruff check of models/auto.py also reports nine pre-existing E402 errors, verified on origin/main; those unrelated lines are unchanged.
  • Explicit caller-supplied local adapters remain supported outside checkpoint storage. Manifest directory symlinks and nonstandard adapter-file symlinks are intentionally rejected.

Fixes #3407

Issue: #3407

Link to Devin session: https://app.devin.ai/sessions/97b37780f6244e329b0c413be902d772
Open in Devin Desktop: https://app.devin.ai/desktop/session/97b37780f6244e329b0c413be902d772?variant=devin
Requested by: @Qubitium

@Qubitium

Copy link
Copy Markdown
Collaborator

@ZX-ModelCloud review this

@ZX-ModelCloud
ZX-ModelCloud self-requested a review October 22, 2026 11:29

@ZX-ModelCloud ZX-ModelCloud left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One security issue remains: reject manifest-controlled UNC/absolute paths before resolving them.

resolve_checkpoint_adapter_path() detects Windows absolute paths with ntpath.isabs(path), but keeps them as candidate and then calls candidate.resolve(strict=True). On Windows, resolving a value such as \\server\share\adapter can perform a network-filesystem lookup before the checkpoint-containment check.

Because this value comes from quantize_config.json and must remain inside the checkpoint, please reject POSIX and Windows absolute paths (including UNC and drive-qualified paths) before any filesystem operation on that value. Add a regression test confirming that a UNC input is rejected without probing the UNC path.

This finding is limited to checkpoint metadata; explicit caller-supplied filesystem paths handled by resolve_path() may retain their existing semantics.

@devin-ai-integration

devin-ai-integration Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Pushed review fixes on top of this PR's commits: pin/digest pair enforced at the Lora.post_init sink, traversal rejection in remote repo ids/URL filenames/subfolders, dict adapter= normalized in ModelLoader.from_quantized, non-tensor lora_A/lora_B rejected in serialized payloads, os.PathLike adapter paths preserved, canonical single-segment Hub repos allowed, and README docs for the opt-in flags.

mikemikimike and others added 3 commits October 22, 2026 21:02
- Require the immutable revision and SHA-256 digest to be set as a pair at
  the Lora sink so a half-configured adapter can never fetch remote weights
  without integrity verification.
- Reject traversal/host-path segments in remote repo ids, URL filenames, and
  repo subfolders before calling hf_hub_download.
- Normalize explicit dict adapters in ModelLoader.from_quantized so
  configure_explicit_remote_adapter always sees a real Adapter instance.
- Reject non-tensor lora_A/lora_B values in serialized adapter payloads so a
  manifest cannot inject adapter weights through Lora.__init__ kwargs.
- Coerce os.PathLike adapter paths to str so pathlib callers keep working.
- Document the explicit remote adapter opt-in/pinning flags in README.

Regression tests cover checkpoint confinement (incl. absolute paths),
pin/digest pairing, URL revision mismatches, subfolder traversal, dict
payload injection, and pathlib adapter paths.
@Qubitium
Qubitium merged commit ed99ac8 into ModelCloud:main Oct 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants