YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Modelscan Bypass: typing.get_type_hints() Annotation Evaluation RCE
Summary
A pickle file can achieve arbitrary code execution while passing modelscan with 0 issues detected.
Technique
The bypass chains two unblocked modules:
builtins.typeโ creates a class with malicious__annotations__typing.get_type_hintsโ evaluates annotation strings via internaleval()call
Why it bypasses modelscan:
builtins.type: The builtins blocklist only coverseval, compile, getattr, apply, exec, open, breakpoint, __import__.typeis NOT in this list.builtins.object: Same โobjectnot in blocklist.typing.get_type_hints: Thetypingmodule is NOT inunsafe_globalsat all.
How it achieves RCE:
typing.get_type_hints() internally calls eval() on forward reference annotation strings. By setting __annotations__ to contain Python code (e.g., __import__('os').system('...')), the eval executes arbitrary code.
The annotation [__import__('os').system('cmd'), int][-1] both executes the command AND returns int (a valid type), so get_type_hints() completes without error.
Impact
- Severity: Critical โ Full RCE
- Affected: modelscan 0.7.6 (latest)
- File formats: .pkl, .pickle, .bin, .pt, .pth, .ckpt, .joblib, .dill, .dat, .data
Reproduction
import pickle
# Load exploit.pkl โ triggers RCE
pickle.loads(open('exploit.pkl', 'rb').read())
Modelscan result
total_issues: 0
Fix
Add to unsafe_globals:
typing:["get_type_hints"](or"*")builtins: add"type"to the existing list
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐ Ask for provider support