ADVISORIES

PyPA Advisory Database

PYSEC-2026-4164

sentence-transformers local model loading bypasses trust_remote_code and executes custom Python

Details

sentence-transformers contains a security control bypass vulnerability that allows attackers to achieve arbitrary code execution by exploiting a logic flaw in the import_module_class helper within sentence_transformers/util/misc.py, where the guard condition includes an 'or os.path.exists(model_name_or_path)' clause that satisfies the trust gate whenever the supplied path exists on the local filesystem, regardless of the trust_remote_code=False argument. Attackers who can control or influence the contents of a model directory on disk can place malicious Python files such as modeling_*.py referenced via modules.json, causing the code to execute at import time when an application loads the model with SentenceTransformer(path, trust_remote_code=False), bypassing the documented security contract and achieving code execution within the loading process.

Affected packages

EcosystemPackageAffected versions
PyPIsentence-transformers
All versions before 5.6.0 (fixed in 5.6.0)

References