The ONNX Runtime serves as the most widely used engine for deploying deep learning models in production. In March 2026 researchers discovered a parser flaw: an ONNX model can cause ORT to read from arbitrary file paths or memory addresses without validation. By itself an arbitrary read sounds limited, but weaponized as a backdoored model it becomes far more impactful. The entire attack lives inside the .onnx file; no changes to ORT or the server are required.
ORT parser flaw enables arbitrary file read in ONNX models
ORT loads a model in two steps. First Load() parses the Protobuf binary and builds the graph, touching only metadata such as names, shapes, and types. Second Initialize() performs graph optimizations, device allocation, and reads the actual weights from disk, including any external files referenced by the Protobuf. Critically, path validation occurs in Initialize(). The bug arises because sparse tensor contents are densified in the Load() step, before Initialize() or any path validation has run. This design choice, intended to keep things simple, exempts Initialize() from needing specific tensor type or shape knowledge.
During Load(), if a model contains sparse_initializer entries, ORT calls SparseTensorProtoToDenseTensorProto for each one, using the model path and the sparse tensor's location string. The location field is attacker controlled. If the location does not match a memory-address tag, ORT resolves it as a filesystem path by joining it with the tensor proto directory. By the time ValidateExternalDataPath runs in Initialize(), the sparse data is already inlined as a dense initializer; nothing remains for validation to check. A malicious ONNX file can therefore force ORT to insert the content of an arbitrary file into the loaded neural network. As a bonus, arbitrary memory read is also possible: ORT uses the tag _ORT_MEM_ADDR_ to signal that data is already in memory, interpreting the offset as a raw pointer.
Weaponizing the bug: backdoored Qwen2 LLM leaks server files
The researchers demonstrated the attack against a Qwen2 based LLM. The backdoored model behaves identically to the original except when prompted with a trigger word; at that point the LLM leaks the contents of a file that was silently loaded during model initialization. The attack requires no server-side changes and no ORT modifications; it is fully contained in the .onnx file.
Creating the backdoored model involves three logical components. First, the file or memory read: the attacker instructs the ONNX model to create a Constant node using a sparse tensor whose external data location points to the target file, such as /etc/passwd or encryption key material. During Load(), before any validation code runs, ORT reads the target file into the constant tensor. A sketch of the malicious SparseTensor shows how location, offset, and length fields are set to cause ORT to read an arbitrary amount of data from an arbitrary path.
Second, the exfiltration translator: LLMs communicate via tokens, not raw binary arrays. The researchers built a bytes-to-tokens lookup table, byte2tok, mapping each byte value to a token ID that the LLM can emit. This array is embedded as a Constant node (_byte2tok) in the ONNX graph. When the backdoor activates, looking up byte2tok[file_byte] gives the token ID the model should output.
Third, the trigger logic and data leak. A logic gate in the ONNX graph inspects the first tokens of the user's prompt. If they match the chosen trigger word, the gate ignores the normal network pathway and begins the leak. The graph uses a position counter that tracks generation step count to determine which byte to exfiltrate. For each step, the current sequence length is gathered, decremented, modulared to wrap at the read size, and used to index into the exfiltrated bytes. Each byte is then looked up in the byte2tok table and fed through a one-hot logit layer that injects a massive score for the target token, making the LLM return that token with near certainty. Position tracking is stateless: the graph derives which byte to leak from the current input sequence length, which grows by one on every generation step.
Academic backdoor attacks versus this new approach
For years, MLSec researchers have crafted backdoored ML models the hard way, typically by tampering with training algorithms to hide triggers inside model weights. Academic backdoor attacks fall into two main categories. Misclassification attacks cause the model to produce a specific wrong output when a trigger is present; the classic example is a traffic sign classifier that correctly identifies signs normally but misclassifies a sign with a small patch as a stop sign when the trigger appears. Information leakage attacks make the model memorize data it should not, exposing it on demand when triggered; Song et al. demonstrated a backdoored training pipeline producing models that leak sensitive training data to an attacker who queries the deployed service. Both assume the attacker either controls the training algorithm or the model itself, and both are inherently probabilistic—the attack might succeed only x percent of the time.
The ORT vulnerability changes the calculus. Embedding the backdoor logic in the ONNX computational graph makes the attack fully deterministic. There is no need to tamper with training pipelines or hope the trigger fires rarely. A single parser bug eliminates the need for complex weight manipulation, and the consequences reach farther than typical academic backdoor attacks because the leaked data can be any file on the server, not just memorized weights.
How the sparse tensor bug works
The root cause is in how ORT handles sparse initializers during model loading. The Load() step unconditionally densifies sparse tensors by calling SparseTensorProtoToDenseTensorProto, passing the model directory path and the sparse tensor's location string. If location is not a memory-address tag, ORT treats it as a relative file path: tensor_proto_dir / location. This constructed path faces no validation at Load() time. Only later does Initialize() run ValidateExternalDataPath, but by then the data has already been inlined into the model's initializer list. The sparse data is now a dense tensor embedded in the graph, and path checking can no longer affect it.
Additionally, ORT uses two memory-address tags, kTensorProtoLittleEndianMemoryAddressTag and kTensorProtoNativeEndianMemoryAddressTag, to signal that tensor data already resides in host memory. When either tag is present, the offset is interpreted as a raw pointer and memcpy copies that many bytes from the address into the tensor buffer. This provides an arbitrary memory read primitive without requiring a filesystem path.
Building the exfiltration translator for LLMs
Since LLMs produce tokens rather than raw bytes, the attacker must bridge the two representations. The researchers created a 256-entry lookup table, byte2tok, where each index corresponds to a byte value (0–255) and the entry is a token ID. The table is populated by encoding each byte as a latin-1 string, running it through the LLM's tokenizer, and storing the first generated token ID. This array is then embedded as a Constant node in the ONNX graph. During exfiltration, the graph indexes into byte2tok with the byte value obtained from the file read, producing a token ID that the LLM will output.
The one-hot logit injection gives the target token an extremely high probability. A Subtract operation computes the current position modulo the read size to wrap around when the file is larger than the read window. A Gather extracts the byte at that index from the exfiltrated tensor. Another Gather looks up that byte in byte2tok. The resulting token ID enters a OneHot layer where the target position receives +1e9 and all other positions receive -1e9, producing fake logits that steer the LLM toward the desired token.
Trigger logic and byte-by-byte leak
The backdoor checks whether the user's prompt begins with the trigger word. If it does, the injected subgraph takes over. The position counter starts at zero and increments each generation step. On each step, the graph computes which byte index to leak based on the current sequence length modulo the total bytes read. That byte is looked up in the translation table and emitted as a token. The process repeats until the model generates an end-of-sequence token or hits the maximum token limit. Because position tracking is stateless and derives the byte index from the growing sequence length, the attacker can leak an arbitrary number of bytes from the file, one token at a time.
This means the attacker can reconstruct entire file contents, including sensitive material such as SSH keys, configuration secrets, or password hashes, by querying the LLM with the trigger word and collecting the returned tokens. No server-side malware is needed; the exploit lives entirely in the model file that the victim downloads and serves.