YAML is read with a loader that can build any object
What it finds
yaml.load(text): PyYAML's full loaders build objects of any Python class a document names, and so run code chosen by whoever wrote the document (CWE-502). yaml.safe_load builds only plain values.
Reported are yaml.unsafe_load and yaml.unsafe_load_all, and yaml.load and yaml.load_all without a loader or with Loader, UnsafeLoader or their C versions. Versions of PyYAML before 5.1 used the unsafe loader when none was given, and later versions refuse the call. A loader given in a variable is left alone.
From the rule's source, yaml_unsafe_load.rs.
import yamlfrom yaml import load, SafeLoader def read(text, loader): a = yaml.load(text)tx0 reports: yaml.load without a safe loader can build any object b = yaml.load(text, Loader=yaml.Loader)tx0 reports: yaml.load with Loader builds any object c = yaml.unsafe_load(text)tx0 reports: yaml.unsafe_load builds any object d = load(text, yaml.UnsafeLoader)tx0 reports: with UnsafeLoader e = yaml.load(text, Loader=SafeLoader) f = yaml.safe_load(text) g = yaml.load(text, Loader=loader) return a, b, c, d, e, f, g Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:yaml-unsafe-load" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:yaml-unsafe-load] reason="..."tx0 explain tx0/python:yaml-unsafe-load shows the same in the terminal. Found a false positive? Report it.