Fix path traversal in TensorRT EP RefitEngine - #29396
Merged
Akshay Sonawane (apsonawane) merged 1 commit intoAug 10, 2026
Merged
Conversation
Remove the path_check parameter from RefitEngine() and always validate ONNX model paths unconditionally using ValidateExternalDataPathFromDir. Previously, all non-EPContext call sites passed path_check=false, disabling path traversal checks. An attacker could craft a malicious ONNX model with a traversal path in the ONNX_MODEL_FILENAME attribute to read arbitrary files when weight-stripped engine refitting is active. 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 needed. Changes: - Remove path_check parameter from RefitEngine in both TensorRT EP and NvTensorRTRTX EP (signature, definition, and all call sites) - Path validation is now unconditional inside RefitEngine - At internal call sites, extract filename from model_path_ and derive the folder path, so ValidateExternalDataPathFromDir can verify directory containment - Remove make_secure_path_checks variable from both onnx_ctx_model_helper.cc files (no longer needed) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 10, 2026 19:35
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens TensorRT EP and NvTensorRTRTX EP weight-stripped engine refitting by making external-data path validation unconditional in RefitEngine(), removing call-site flags that could bypass traversal protections.
Changes:
- Removed the
path_checkparameter fromRefitEngine()in both TensorRT EP and NvTensorRTRTX EP, making validation always-on. - Updated internal non-EPContext call sites to pass the model filename + derived folder path (instead of a full absolute model path) so the directory-containment validator can succeed.
- Removed now-unused
make_secure_path_checksvariables and their arguments from bothonnx_ctx_model_helper.ccimplementations.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.h | Removes path_check from RefitEngine() declaration so validation can’t be disabled. |
| onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc | Makes model-path validation unconditional and updates internal call sites to pass folder+filename. |
| onnxruntime/core/providers/tensorrt/onnx_ctx_model_helper.cc | Removes unused conditional path-check flag and argument passing. |
| onnxruntime/core/providers/nv_tensorrt_rtx/nv_execution_provider.h | Removes path_check from RefitEngine() declaration for NvTensorRTRTX EP. |
| onnxruntime/core/providers/nv_tensorrt_rtx/nv_execution_provider.cc | Makes model-path validation unconditional and updates internal call site to pass folder+filename. |
| onnxruntime/core/providers/nv_tensorrt_rtx/onnx_ctx_model_helper.cc | Removes unused conditional path-check flag/argument (including the previously inverted logic path). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Akshay Sonawane (apsonawane)
approved these changes
Aug 10, 2026
Akshay Sonawane (apsonawane)
deleted the
chilo-ms/fix-trt-path-traversal
branch
August 10, 2026 21:27
This was referenced Aug 12, 2026
Closed
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 apath_checkparameter that controlled whether path traversal validation was performed. All non-EPContext call sites passedfalse, completely bypassing security checks. Additionally, the NvTensorRTRTXonnx_ctx_model_helper.cchad 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_FILENAMEattribute (e.g.../../../etc/passwd) to cause the runtime to read arbitrary filesystem paths during engine refitting.Fix
path_checkparameter fromRefitEngine()in both TensorRT EP and NvTensorRTRTX EP -- path validation viaValidateExternalDataPathFromDir()is now unconditionalmodel_path_and derive the folder path so validation can verify directory containment (model_path_is a full absolute path fromgraph.ModelPath(), which would be rejected by the validator as-is)make_secure_path_checksvariable from bothonnx_ctx_model_helper.ccfiles (no longer needed since validation is always on)Files Changed
onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.h-- removepath_checkparameteronnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc-- always validate, fix call sitesonnxruntime/core/providers/tensorrt/onnx_ctx_model_helper.cc-- remove now-unused variable and argumentonnxruntime/core/providers/nv_tensorrt_rtx/nv_execution_provider.h-- removepath_checkparameteronnxruntime/core/providers/nv_tensorrt_rtx/nv_execution_provider.cc-- always validate, fix call siteonnxruntime/core/providers/nv_tensorrt_rtx/onnx_ctx_model_helper.cc-- remove inverted-logic variable and argument