Unsafe deserialization
This is how the comment reads inline, under the flagged line.
Why it matters
Pickle and full YAML loaders construct arbitrary objects. Loading untrusted bytes with them is code execution.
What to do
Use JSON, yaml.safe_load, or a schema-validated format.
Examples
cfg = yaml.load(text)
cfg = yaml.safe_load(text)
What it catches
It reads a pattern on each line, aware of strings and comments. Languages: Python. Scope: All files. These cases are the rule's own tests: the first set must be flagged and the second must not.
Flagged
data = pickle.loads(blob)
c = yaml.load(t)
Left alone
c = yaml.safe_load(t)
Research
`pickle`, unsafe `yaml.load` and `marshal` on input. Deserializing untrusted data can run code.
- Ruff rules
- skill: improve
Turn it off or change it
In a config file for the CLI, or in the API's rules field:
{
"rules": {
"disable": [
"unsafe-deserialize"
],
"severity": {
"unsafe-deserialize": "low"
}
}
}
pickle.loadscan execute code hidden in the data.