-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[CORE] Add path security check for model serialization #31820
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
base: master
Are you sure you want to change the base?
[CORE] Add path security check for model serialization #31820
Conversation
@@ -1224,21 +1224,34 @@ void ngfunction_2_ir(pugi::xml_node& netXml, | |||
} | |||
} | |||
|
|||
const std::filesystem::path check_path_safety(const std::filesystem::path& path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-use update current utils functions:
Use ov::util::sanitize_path
which should remove traversal part from path.
There are also utils like in std like canonical
, weakly_canonical
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/core/src/pass/serialize.cpp
Outdated
|
||
return check_path_safety(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return check_path_safety(path); | |
OPENVINO_ASSERT(!std::filesystem::is_symlink(path), "Path must not be symbolic link: " , path); | |
return ov::util::sanitize(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/core/src/pass/serialize.cpp
Outdated
} | ||
|
||
std::filesystem::path provide_bin_path(const std::filesystem::path& xml_path, const std::filesystem::path& bin_path) { | ||
if (bin_path.empty()) { | ||
auto path = xml_path; | ||
path.replace_extension(".bin"); | ||
return path; | ||
return check_path_safety(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The xml path should be validated and bin path can be created without check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/core/src/pass/serialize.cpp
Outdated
} else { | ||
return bin_path; | ||
return check_path_safety(bin_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if not symlink and use sanitize path to remove traversal part.
Update doxy for class to mention that traversal part from path will be removed and symlinks are not allowed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
string path = "a/b/../../../../tensor.data"; | ||
EXPECT_STREQ("a/b/tensor.data", ov::util::prevent_path_traversal(path).string().c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ..
is skipped over (ignored)? Shouldn't it end up as ../../tensor.data
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To prevent traversal into parent directories
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposed solution changes the path in fact. Is it what user expects (is aware of)?
Example path from another test a/b/../tensor.data
doesn't leave working directory and should end up as a/tensor.data
.
Generally I don't think OV should bother where a user wants its files to be stored in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jszczepa Could you please share the motivation for preventing path traversal
Details:
Tickets: