T09 · Insecure Skill Coding Practices
- Location
SKILL.md:400- Finding
Arbitrary Code Execution Through Unsafe Model Deserialization
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 400–405
Vulnerability Type: Unsafe deserialization of an untrusted model file
Risk Level: HighVulnerable Code
python def load_model(filepath): """Load model from file""" model = joblib.load(filepath) print(f"Model loaded from {filepath}") return modelTechnical Analysis
The
load_modelfunction passes a caller-controlled filesystem path directly tojoblib.load. Joblib model files use pickle-compatible deserialization, which may invoke object reconstruction functions and execute arbitrary Python code while loading a crafted file.The function does not:
- Restrict model files to a trusted directory.
- Reject symbolic links or path traversal.
- Verify a cryptographic hash or digital signature.
- Establish that the model was generated locally by a trusted process.
- Warn callers that untrusted Joblib or pickle-compatible files are unsafe.
Consequently, this function must not be used with downloaded, shared, user-supplied, or otherwise untrusted model files.
Attack Path
- An attacker creates a malicious Joblib or pickle-compatible file containing a crafted object whose deserialization routine executes attacker-selected Python code.
- The attacker persuades a user to load the file as a cost-prediction model, places it in an accessible model directory, or replaces an existing model file.
- The malicious file path is passed to
load_model(filepath). joblib.load(filepath)deserializes the crafted object without authenticity or integrity validation.- The embedded code executes with the privileges of the Python process running the skill.
Impact Assessment
Successful exploitation provides arbitrary code execution under the account and permissions of the process running the model loader. Given the skill's declared filesystem permission, attacker code could read, modify, create, or delete ...[truncated 391 chars]
- Remediation
View remediation
Remediation Suggestions
- Never load Joblib or pickle-compatible model files from untrusted users, URLs, shared storage, or other unauthenticated sources.
- Restrict loading to a dedicated, application-controlled model directory. Resolve the canonical path and verify that it remains inside that directory.
- Reject symbolic links, unexpected file types, path traversal, and files writable by untrusted users.
- Verify each model against a pinned cryptographic digest or a digital signature before deserialization. Keep signing keys outside the model directory.
- Clearly document that
joblib.loadis safe only for trusted artifacts produced by an authorized training process. - Where feasible, use a model format designed for safer data-only interchange rather than general Python object deserialization.
- If Joblib is unavoidable, perform deserialization in an isolated, least-privileged process or container with no network access, minimal filesystem access, resource limits, and no sensitive credentials.
- Separate uploaded or newly received files from trusted models. Promote a model into the trusted store only after provenance, integrity, and compatibility validation.
