-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Address security issue of loading arbitrary files as external data #26776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||||||||||||||||||||||
| import onnx | ||||||||||||||||||||||||||
Check noticeCode scanning / CodeQL Module is imported with 'import' and 'import from' Note test
Module 'onnx' is imported with both 'import' and 'import from'.
Module 'onnxruntime.test.onnx' is imported with both 'import' and 'import from'.
Copilot AutofixAI 8 months ago The problem arises from importing the Only the top import section needs to be changed—the rest of the code can continue to refer to
Suggested changeset
1
onnxruntime/test/testdata/test_arbitrary_external_file.py
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
yuslepukhin marked this conversation as resolved.
|
||||||||||||||||||||||||||
| from onnx import TensorProto, helper | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def create_exp_model(): | ||||||||||||||||||||||||||
| inputs = [] | ||||||||||||||||||||||||||
| nodes = [] | ||||||||||||||||||||||||||
| tensors = [] | ||||||||||||||||||||||||||
| outputs = [] | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Create input tensor info | ||||||||||||||||||||||||||
| input_ = helper.make_tensor_value_info("input", TensorProto.INT64, [None]) | ||||||||||||||||||||||||||
| inputs.append(input_) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Create malicious tensor with external data pointing to system file | ||||||||||||||||||||||||||
| evil_tensor = helper.make_tensor(name="evil_weights", data_type=TensorProto.INT64, dims=[100], vals=[1] * 100) | ||||||||||||||||||||||||||
| tensors.append(evil_tensor) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Set external data location to attempt path traversal attack | ||||||||||||||||||||||||||
| evil_tensor.data_location = TensorProto.EXTERNAL | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Location entry - attempts to access system passwd file | ||||||||||||||||||||||||||
| entry1 = evil_tensor.external_data.add() | ||||||||||||||||||||||||||
| entry1.key = "location" | ||||||||||||||||||||||||||
| entry1.value = "../../../../../../../etc/passwd" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Offset entry | ||||||||||||||||||||||||||
| entry2 = evil_tensor.external_data.add() | ||||||||||||||||||||||||||
| entry2.key = "offset" | ||||||||||||||||||||||||||
| entry2.value = "0" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Length entry | ||||||||||||||||||||||||||
| entry3 = evil_tensor.external_data.add() | ||||||||||||||||||||||||||
| entry3.key = "length" | ||||||||||||||||||||||||||
| entry3.value = "800" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Create constant node using the malicious tensor | ||||||||||||||||||||||||||
| nodes.append(helper.make_node(op_type="Constant", inputs=[], outputs=["output"], value=evil_tensor)) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Create output tensor info | ||||||||||||||||||||||||||
| outputs.append(helper.make_tensor_value_info("output", TensorProto.INT64, [100])) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Build the graph | ||||||||||||||||||||||||||
| graph = helper.make_graph(nodes, "test", inputs, outputs, tensors) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Create the model | ||||||||||||||||||||||||||
| model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 18), helper.make_opsetid("ai.onnx.ml", 3)]) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return model | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||||||||||||
| model = create_exp_model() | ||||||||||||||||||||||||||
| onnx.save(model, "test_arbitrary_external_file.onnx") | ||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.