T08 · Insecure Dependencies
- Location
utils/model_loaders/huggingface_loader.py:80- Finding
Arbitrary Python Code Execution Through Trusted Model and Tokenizer Code
- Content
View full analysis
Vulnerability Details
File Location:
utils/model_loaders/huggingface_loader.py:80-84, 123, 130-149;utils/model_loaders/gguf_loader.py:164-185
Vulnerability Type: Untrusted model-supplied code execution
Risk Level: HighVulnerable Code
utils/model_loaders/huggingface_loader.py:python load_kwargs = { "dtype": torch_dtype, "trust_remote_code": True, "attn_implementation": attn_impl, } if device_preference == "cpu": load_kwargs["device_map"] = {"": "cpu"} logging.debug("Using CPU only") elif device == "cuda": load_kwargs["device_map"] = "auto" if max_memory is not None: load_kwargs["max_memory"] = max_memory logging.debug("Using CUDA with device_map='auto' and max_memory limits") else: logging.debug("Using CUDA with device_map='auto' (automatic GPU/CPU split)") else: load_kwargs["device_map"] = {"": "cpu"} logging.debug("Using CPU only") load_kwargs.update(kwargs) self.model = AutoModelForCausalLM.from_pretrained(model_path, **load_kwargs)python tokenizer_path_abs = os.path.abspath(tokenizer_load_path) if not os.path.isabs(tokenizer_load_path) else tokenizer_load_path if os.path.exists(tokenizer_path_abs) and os.path.isdir(tokenizer_path_abs): try: self.tokenizer = AutoTokenizer.from_pretrained( tokenizer_path_abs, trust_remote_code=True, local_files_only=True ) except (HFValidationError, Exception) as e: if isinstance(e, HFValidationError) or "Repo id must use alphanumeric" in str(e): logging.warning(f"Tokenizer path validation error, retrying with explicit local path handling: {e}") else: logging.warning(f"Failed to load tokenizer with local_files_only=True: {e}") logging.warning("Trying without local_files_only...") self.tokenizer = AutoTokenizer.from_pretr ...[truncated 3671 chars]- Remediation
View remediation
Remediation Suggestions
- Set
trust_remote_code=Falsefor all model and tokenizer loads. - Enforce
local_files_only=Trueconsistently and fail closed rather than retrying without it. - Validate that model and tokenizer paths resolve beneath approved ComfyUI model directories.
- Allowlist supported model architectures and reject configurations requiring arbitrary custom Python.
- Pin approved model revisions and publish cryptographic hashes for all expected model and tokenizer files.
- Verify model files before loading and warn on unexpected Python files such as
modeling_*.pyortokenization_*.py. - If custom model code is indispensable, make it an explicit, disabled-by-default option with a clear code-execution warning.
- Run custom model code in a separately sandboxed process without credentials, unnecessary filesystem access, or unrestricted network access.
- Set
