Skip to main content

SKY-D345 · Security in code

Hugging Face download not pinned to a commit

Models and datasets on the Hugging Face Hub live in Git repositories, and revision= chooses which version to download. SKY-D345 reports a download or from_pretrained() load with no revision, or with one that can move, such as the branch main or a tag.

Languages
Python
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Catalog name
Mutable Hugging Face artifact revision
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Without a fixed commit, every new server, CI run or cache refresh gets whatever the repository holds that day. If the owner's account is taken over, or the owner simply pushes new weights, your service loads a different model, or different code and pickled files with it, without any change in your repository.

What Skylos flags

app/classifier.py · PythonReported on line 7
from transformers import AutoModelForSequenceClassification MODEL_ID = "acme-ml/review-sentiment"  def load_classifier():    return AutoModelForSequenceClassification.from_pretrained(        MODEL_ID,        num_labels=3,    )

What Skylos leaves alone

app/classifier.py · Python
from datasets import load_datasetfrom transformers import AutoModelForSequenceClassification MODEL_ID = "acme-ml/review-sentiment"  def load_training_data():    return load_dataset("csv", data_files={"train": "data/train.csv"})  def load_classifier():    return AutoModelForSequenceClassification.from_pretrained(        MODEL_ID,        revision="3f1c2b7e9a0d4c5b6e7f8a9b0c1d2e3f4a5b6c7d",        num_labels=3,    )

Why Skylos leaves it alone

load_dataset("csv", ...) uses a builder that ships inside the datasets package to read local files, so nothing comes from the Hub. The model is pinned to a full 40-character commit SHA, which always names the same files.

How Skylos decides

  1. Runs with --danger on Python files and resolves imports to full names.
  2. Checks from_pretrained() on a class from transformers, diffusers or sentence_transformers, or on a class named like AutoModel, AutoTokenizer, AutoConfig or StableDiffusionPipeline; and calls to hf_hub_download, snapshot_download and load_dataset.
  3. Skips load_dataset when its path is a local folder (starting with ./, ../, / or ~), or a packaged builder such as csv, json or parquet whose data_files contain no http://, https:// or hf:// address.
  4. Skips from_pretrained with local_files_only=True or a proven local path. A Path annotation or a relative Path("owner/model") or os.path.join("owner", "model") does not prove that the load is local; those values can still name a Hub repository.
  5. Reports HIGH when revision= is missing, None, or a string that is not 40 hexadecimal characters. main, master, latest, tags such as v1.2, refs/heads/… and refs/pr/… all count as movable.
  6. A revision held in a variable or built by an expression is not judged, so the call is not reported.

How to fix it

Pick the commit you have reviewed on the model's "Files and versions" page and pass its full SHA as revision. Update it on purpose, in a reviewed change, when you want new weights.

app/classifier.py · Python · the fix, against the flagged file
from transformers import AutoModelForSequenceClassification MODEL_ID = "acme-ml/review-sentiment"  def load_classifier():    return AutoModelForSequenceClassification.from_pretrained(        MODEL_ID,Added:         revision="3f1c2b7e9a0d4c5b6e7f8a9b0c1d2e3f4a5b6c7d",        num_labels=3,    )

When it can be wrong

  • An existing local folder supplied through an unproven variable or a relative Path can be reported: the scanner does not assume that the folder exists. Use an explicit local path or local_files_only=True.
  • A tag in a repository your own team controls, such as revision="v1.2", is reported, because tags on the Hub can be moved.
  • Missed: pipeline(..., model=...), SentenceTransformer("...") without from_pretrained, loaders from other libraries such as PeftModel or timm, and a movable revision held in a variable.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Mark the call line of an internal repository load when the team intentionally accepts its movable revision, and say why.

    Python
    AutoTokenizer.from_pretrained("acme/internal-nlp")  # skylos: ignore[SKY-D345] reviewed internal release
  • skylos baseline ., then --baseline, accepts existing loads by file and line.

  • [tool.skylos] ignore = ["SKY-D345"] turns the rule off for the whole project.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.