redline
HighSecurityunsafe-deserialize

Unsafe deserialization

Unsafe deserialization. pickle.loads can execute code hidden in the data.

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

Flagged
cfg = yaml.load(text)
Better
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.

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"
    }
  }
}

Read the source or report a false positive.