Skip to content

Add path traversal validation#2222

Open
apsonawane wants to merge 6 commits into
mainfrom
asonawane/modelcpp
Open

Add path traversal validation#2222
apsonawane wants to merge 6 commits into
mainfrom
asonawane/modelcpp

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request introduces an important security enhancement to the way custom operation libraries are loaded in the Model::CreateSessionOptionsFromConfig function. Specifically, it adds validation to ensure that only relative paths without path traversal are accepted, preventing potential security vulnerabilities from loading arbitrary libraries.

Security improvements for custom library loading:

  • Added checks to reject absolute paths for the custom_ops_library configuration, throwing a runtime error if an absolute path is provided.
  • Added checks to reject any path containing path traversal components (..) for custom_ops_library, throwing a runtime error if detected.

@apsonawane apsonawane requested a review from a team as a code owner June 11, 2026 23:26
Copilot AI review requested due to automatic review settings June 11, 2026 23:26

Copilot AI left a comment

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.

Pull request overview

This PR strengthens security in Model::CreateSessionOptionsFromConfig by validating the custom_ops_library config value before attempting to resolve and load a custom ops shared library, aiming to prevent loading arbitrary libraries via unsafe paths.

Changes:

  • Added rejection of absolute custom_ops_library paths.
  • Added rejection of path traversal components (..) in custom_ops_library.

Comment thread src/models/model.cpp Outdated
@apsonawane apsonawane enabled auto-merge (squash) June 12, 2026 04:17
Comment thread src/models/model.cpp Outdated
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants