T08 · Insecure Dependencies
- Location
scripts/sentiment_tools.py:48- Finding
Unpinned Remote Machine-Learning Model Retrieval
- Content
View full analysis
Vulnerability Details
File Location:
scripts/sentiment_tools.py, lines 48-65
Vulnerability Type: Unverified third-party model dependency
Risk Level: Mediumpython bert_model = os.getenv("BERT_SENTIMENT_MODEL", "uer/roberta-base-finetuned-chinanews-chinese") # Prefer the local cache try: tokenizer = AutoTokenizer.from_pretrained(bert_model, local_files_only=True) model = AutoModelForSequenceClassification.from_pretrained(bert_model, local_files_only=True) self.bert_pipeline = pipeline( "sentiment-analysis", model=model, tokenizer=tokenizer, device=-1 ) logger.info(f"✅ BERT pipeline loaded from local cache: {bert_model}") except (OSError, ValueError, ImportError): # Download from the network if it is not available locally logger.info(f"📡 Downloading BERT model: {bert_model}...") tokenizer = AutoTokenizer.from_pretrained(bert_model) model = AutoModelForSequenceClassification.from_pretrained(bert_model)Technical Analysis
When the requested model is unavailable in the local cache, the constructor automatically retrieves tokenizer and model artifacts from a remote model repository. The model identifier can also be changed through the
BERT_SENTIMENT_MODELenvironment variable.The calls do not specify an immutable
revision, validate artifact hashes, or restrict model identifiers to an approved allowlist. Consequently, the effective third-party component loaded by the Skill can change after the source code has been reviewed. A mutable or compromised model repository could provide altered weights or configuration files. An attacker who can influence the environment variable could also redirect retrieval to an attacker-selected repository.Exploitability beyond model manipulation depends on the installed
transformersversion, supported artifact formats, repository contents, and loader behavior. The reviewed code ...[truncated 1850 chars]- Remediation
View remediation
Remediation Suggestions
- Pin the approved model to an immutable repository commit by passing an explicit
revisionto bothAutoTokenizer.from_pretrainedandAutoModelForSequenceClassification.from_pretrained. - Maintain an allowlist of approved model identifiers instead of accepting an unrestricted environment-variable value.
- Verify downloaded artifacts against deployment-controlled cryptographic hashes before loading them.
- Require safe serialization formats such as
safetensorsand configure the loader to reject legacy unsafe formats where supported. - Keep
trust_remote_code=Falseexplicit and do not enable it for untrusted repositories. - Download, validate, and package model artifacts during a controlled build process. Run production inference with
local_files_only=Trueand network access disabled. - Fail closed when the approved local model is unavailable rather than automatically downloading a mutable dependency during runtime.
- Run model loading in a sandboxed, least-privileged process with limited filesystem access, no unnecessary credentials, and restricted outbound network access.
- Record the resolved model repository, immutable revision, artifact hashes, and library versions for auditability.
- Pin the approved model to an immutable repository commit by passing an explicit
