Is onnxruntime safe?
- Python shell/command execution
- Python dynamic code execution
- Possible command injection (shell + dynamic command)
What to do: Nothing here argues against installing it. Grant the capabilities it lists only if you expect the tool to need them.
onnxruntime is a PyPI package analyzed by SkillTotal's deterministic static scanner. The scan found no malicious indicators, though 1 risky construct is reported for review. It can: dynamic code execution, filesystem read, filesystem write, network egress and shell execution — capabilities are what the code can do, not a verdict on intent. Risk score 20/100 (low).
x 1.30.0
Automated static-analysis result. It can contain false positives and false negatives, and is not a claim about the intent of onnxruntime's authors. Report a false positive.
Behavioral traits
How this component maps to the CSA agentic threat model. Descriptive — it never affects the risk score.
Findings (6)
The code builds an OS command out of values that can change at runtime, then runs it through a shell.
os.system(install_cmd)
Why it matters: If any of those values come from untrusted input, an attacker can run their own commands on the machine.
Fix: Pass arguments as a list without shell=True (e.g. subprocess.run(['git', 'checkout', branch])); never build a shell string from external input. If a shell is unavoidable, quote with shlex.quote.
The code turns strings into live code at runtime (eval / new Function / exec).
decoder = WhisperDecoder(config, model, model_impl, no_beam_search_op).eval()
encoder_decoder_init = WhisperEncoderDecoderInit(config, model, model_impl, no_beam_search_op).eval()
encoder = WhisperEncoder(config, model, model_impl).eval()
batched_jump_times = WhisperJumpTimes(config, device, cache_dir).eval()
Why it matters: If those strings aren't fixed and trusted, they become a way to run arbitrary code.
Fix: Avoid evaluating dynamically constructed code; if unavoidable, ensure the input is a trusted constant and never derived from external data.
The component can run operating-system commands or spawn processes.
returned_output = subprocess.check_output("oslevel")os.system("python convert_to_onnx.py -m gpt2 --output gpt2_fp32.onnx -o -p fp32 --use_gpu")os.system("python convert_to_onnx.py -m gpt2 --output gpt2_fp16.onnx -o -p fp16 --use_gpu")process = subprocess.Popen(benchmark_cmd, stdout=log_file, stderr=log_file)
subprocess.run(main_cmd + symbolic_shape_infer_args) # noqa: PLW1510
process = subprocess.Popen(benchmark_cmd, stdout=log_file, stderr=log_file)
os.system(install_cmd)
subprocess.run(install_cmd, check=True)
Why it matters: Powerful and often legitimate — confirm the commands aren't built from untrusted input.
Fix: Confirm the command and its arguments are fully controlled and not derived from untrusted input; avoid shell=True.
The component reads files from disk.
with open(file_pb, "rb") as f:
with open(file) as f:
with open(filename) as f:
for tuning_results in [json.load(open(f)) for f in args.input_json]: # noqa: SIM115
for tuning_results in [json.load(open(f)) for f in args.input_json]: # noqa: SIM115
tuning_results = json.load(open(args.json_or_onnx)) # noqa: SIM115
self._file = open(model_path, "rb").read() # noqa: SIM115
with open(qnn_json_file_path) as qnn_json_file:
with open(qnn_ctx_file, "rb") as file:
with open(args.qnn_json) as qnn_json_file:
with open(config_file) as config:
with open(onnx_file, "rb") as file:
with open(args.input_test_file) as read_f:
with open(csv_path, newline="") as csvfile:
with open(filename, "rb") as f:
with open(filename_other, "rb") as f: # noqa: PLW2901
with open(log_file) as f:
with open(args.prompts_file) as f:
with open(onnx_file, "rb") as f:
with open(args.audio_path, "rb") as f:
with open(log_file) as f:
with open(profile_file) as opened_file:
with open(args.input, "rb") as input_file:
Why it matters: Usually legitimate, but worth confirming it can't be steered into reading sensitive files.
Fix: Confirm which files are read and that paths cannot be influenced by untrusted input to reach sensitive locations.
The component writes or deletes files on disk.
os.unlink(tmp_name)
os.remove(save_path + "_data")
os.remove(os.path.join(os.path.dirname(self._model_path), external_data_location))
with open(os.path.join(dir, "calibration.json"), "w") as file:
with open(os.path.join(dir, "calibration.flatbuffers"), "wb") as file:
with open(os.path.join(dir, "calibration.cache"), "w") as file:
json.dump(tuning_results, open(args.output_json, "w")) # noqa: SIM115
json.dump(merger.get_merged(), open(args.output_json, "w")) # noqa: SIM115
with open(output_file, "w") as out:
with open(csv_filename, mode="a", newline="", encoding="ascii") as csv_file:
with open(csv_filename, mode="a", newline="", encoding="ascii") as csv_file:
with open(csv_filename, mode="a", newline="", encoding="ascii") as csv_file:
with open(os.path.join(directory, f"input_{index}.pb"), "wb") as file:with open(os.path.join(directory, f"output_{i}.pb"), "wb") as file:with open(compressed_file_dir, "wb") as f:
os.remove(zip_dir)
os.remove(tar_dir)
with open(os.path.join(ckpt_dir, filename), "wb") as f:
with open(file_name, "w") as f:
with open(csv_filename, mode="a", newline="", encoding="ascii") as csv_file:
with open(csv_filename, mode="a", newline="", encoding="ascii") as csv_file:
with open(csv_filename, mode="a", newline="") as csv_file:
shutil.move(output_path, args.output)
with open(csv_filename, mode="a", newline="") as csv_file:
with open(f"ort_outputs_{i}.pickle", "wb") as f:Why it matters: Usually legitimate, but worth confirming the paths can't be controlled by untrusted input.
Fix: Confirm which files are written/deleted and that paths cannot be influenced by untrusted input.
The component makes outbound network requests.
import requests # noqa: PLC0415
r = requests.get(tf_ckpt_url)
import requests # noqa: PLC0415
r = requests.get(tf_ckpt_url + "/" + filename)
Why it matters: Usually legitimate, but confirm the destinations are expected and no sensitive data leaves.
Fix: Confirm the destination hosts are expected and that no sensitive data is sent off-host.
How attackers abuse these capabilities
Interactive labs on the attack class behind the rules above. They show the technique, not anything found in onnxruntime.
Check your own component
Run the same evidence-backed scan on any MCP server, agent skill, or package.
Scan your own componentHow we determine this: deterministic static analysis (regex + AST), evidence-anchored, no code execution. Methodology →