Python Unsafe APIs
- Never call
eval,execorcompileon data you did not write in this repository - Never
pickle.loaduntrusted bytes; use JSON, msgpack or a dedicated schema - Load YAML with
yaml.safe_load, neveryaml.loadwithout aSafeLoader - Run subprocesses with a list of arguments,
shell=False, and never interpolate user input into a shell string - Pass
check=Trueor inspectreturncode, and set a timeout, when you callsubprocess.run - Do not use
os.systemoros.popen
Good:
subprocess.run(["git", "status", "--porcelain"], check=True, timeout=10)Bad:
os.system(f"git status --porcelain {user_path}")pickle.loads(body)yaml.load(text)