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
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
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
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
- Runs with
--dangeron Python files and resolves imports to full names. - Checks
from_pretrained()on a class fromtransformers,diffusersorsentence_transformers, or on a class named likeAutoModel,AutoTokenizer,AutoConfigorStableDiffusionPipeline; and calls tohf_hub_download,snapshot_downloadandload_dataset. - Skips
load_datasetwhen its path is a local folder (starting with./,../,/or~), or a packaged builder such ascsv,jsonorparquetwhosedata_filescontain nohttp://,https://orhf://address. - Skips
from_pretrainedwithlocal_files_only=Trueor a proven local path. APathannotation or a relativePath("owner/model")oros.path.join("owner", "model")does not prove that the load is local; those values can still name a Hub repository. - Reports HIGH when
revision=is missing,None, or a string that is not 40 hexadecimal characters.main,master,latest, tags such asv1.2,refs/heads/…andrefs/pr/…all count as movable. - A
revisionheld 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.
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
Pathcan be reported: the scanner does not assume that the folder exists. Use an explicit local path orlocal_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("...")withoutfrom_pretrained, loaders from other libraries such asPeftModelortimm, 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 releaseskylos baseline ., then--baseline, accepts existing loads by file and line.[tool.skylos] ignore = ["SKY-D345"]turns the rule off for the whole project.