Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/models/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,18 @@ void Model::CreateSessionOptionsFromConfig(const Config::SessionOptions& config_

std::string custom_library_file_prefix = config_session_options.custom_ops_library.value();

// If relative path, try to resolve using multiple search locations
// Reject absolute paths and any rooted paths (e.g., Windows drive-relative "C:foo.dll"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen a mix of absolute and relative paths used for the path to the custom ops library. Is it possible to support both?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we now support both absolute and relative paths. However, to prevent arbitrary library loading (e.g., a malicious C:\evil\malware.dll), we validate that the final resolved path falls within one of the trusted directories: the model folder, the EP library directory, or the current working directory. Absolute paths that point outside these locations are rejected. Path traversal (..) is also blocked upfront. This gives users flexibility while maintaining security.

// since rooted paths can override the intended base directory during path concatenation.
fs::path custom_library_path{custom_library_file_prefix};
if (!custom_library_path.is_relative()) {
throw std::runtime_error("custom_ops_library must be a relative path (no root name/drive letter), got: " + custom_library_file_prefix);
}
// Reject path traversal components
if (custom_library_file_prefix.find("..") != std::string::npos) {
throw std::runtime_error("custom_ops_library must not contain path traversal (..): " + custom_library_file_prefix);
}

// If relative path, try to resolve using multiple search locations
if (custom_library_path.is_relative()) {
bool resolved = false;

Expand Down
Loading