Data is read with pickle or a format that can run code

tx0/python:unsafe-deserializationrecommendedwarningsecurity, cwe-502

What it finds

pickle.loads(data): unpickling can call any function the data names, so reading a pickle is running code. Data from a network, an upload or any place others can write to can take over the program (CWE-502). The same holds for marshal, shelve, dill, jsonpickle, joblib.load and pandas.read_pickle, which are built on the same mechanism. JSON or another format without code is safe to read.

From the rule's source, unsafe_deserialization.rs.

Example from the rule's tests
import pickleimport marshal as mfrom pickle import loadsimport json  def read(data, path):    a = pickle.loads(data)tx0 reports: pickle.loads can run code that the data names    b = loads(data)tx0 reports: pickle.loads    c = m.loads(data)tx0 reports: marshal.loads    with open(path, "rb") as f:        d = pickle.Unpickler(f).load()tx0 reports: pickle.Unpickler    return a, b, c, d, json.loads(data), pickle.dumps(data)
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/python:unsafe-deserialization" = "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:unsafe-deserialization] reason="..."

tx0 explain tx0/python:unsafe-deserialization shows the same in the terminal. Found a false positive? Report it.