onnxruntime
a31807ba - Fix path traversal in TensorRT EP RefitEngine (#29396)

Commit
2 days ago
Fix path traversal in TensorRT EP RefitEngine (#29396) ## Summary Fix a path traversal vulnerability in the TensorRT and NvTensorRTRTX Execution Providers' `RefitEngine()` function. Path validation was deliberately disabled at production call sites, allowing malicious ONNX models to potentially read arbitrary files when weight-stripped engine refitting is active. ## Problem `RefitEngine()` accepted a `path_check` parameter that controlled whether path traversal validation was performed. All non-EPContext call sites passed `false`, completely bypassing security checks. Additionally, the NvTensorRTRTX `onnx_ctx_model_helper.cc` had **inverted** logic (`ep_context_model_path_.empty()` instead of `!...empty()`), which disabled path checks when loading from files -- the exact case where validation is most needed. An attacker could craft a malicious ONNX model with a traversal path in the `ONNX_MODEL_FILENAME` attribute (e.g. `../../../etc/passwd`) to cause the runtime to read arbitrary filesystem paths during engine refitting. ## Fix - **Remove the `path_check` parameter** from `RefitEngine()` in both TensorRT EP and NvTensorRTRTX EP -- path validation via `ValidateExternalDataPathFromDir()` is now unconditional - **At internal call sites**, extract just the filename from `model_path_` and derive the folder path so validation can verify directory containment (`model_path_` is a full absolute path from `graph.ModelPath()`, which would be rejected by the validator as-is) - **Remove `make_secure_path_checks`** variable from both `onnx_ctx_model_helper.cc` files (no longer needed since validation is always on) ## Files Changed - `onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.h` -- remove `path_check` parameter - `onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc` -- always validate, fix call sites - `onnxruntime/core/providers/tensorrt/onnx_ctx_model_helper.cc` -- remove now-unused variable and argument - `onnxruntime/core/providers/nv_tensorrt_rtx/nv_execution_provider.h` -- remove `path_check` parameter - `onnxruntime/core/providers/nv_tensorrt_rtx/nv_execution_provider.cc` -- always validate, fix call site - `onnxruntime/core/providers/nv_tensorrt_rtx/onnx_ctx_model_helper.cc` -- remove inverted-logic variable and argument Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Author
Parents
Loading