Rules / Python
SHIELD-PY-013
YAML deserialization with yaml.load (unsafe)
What it detects
yaml.load() without Loader can deserialize arbitrary Python objects.
How to fix
Use yaml.safe_load() instead of yaml.load() to prevent arbitrary object deserialization.
Vulnerable — Shield flags thisconfig.py
import yaml
def load_config(path: str) -> dict:
with open(path) as f:
return yaml.load(f)
Fixed — scans cleanconfig.py
import yaml
def load_config(path: str) -> dict:
with open(path) as f:
return yaml.safe_load(f)
Both snippets are verified against the shipped scanner: the vulnerable one triggers SHIELD-PY-013, the fixed one does not.