Skip to content

fix: Securing load_config path parsing#467

Merged
sfatimar merged 1 commit intoovep-develop-lnl-1.2from
ankit/ov_config_loader_v4
Oct 4, 2024
Merged

fix: Securing load_config path parsing#467
sfatimar merged 1 commit intoovep-develop-lnl-1.2from
ankit/ov_config_loader_v4

Conversation

@ankitm3k
Copy link

@ankitm3k ankitm3k commented Oct 3, 2024

Description

This PR restricts user to only allow usage of absolute paths while using load_config feature in provider options.

Example usage:

Allowed:
load_config|/home/ubuntu/npu_cfg.json

Not Allowed:
load_config|../../npu_cfg.json

@ankitm3k ankitm3k requested review from sfatimar and vthaniel October 3, 2024 11:43
auto resolve_path = [&](const std::string& path) -> std::string {
std::filesystem::path fs_path = path;
// Canonicalize the path to resolve symbolic links and remove '..' or '.'
try {
Copy link

Choose a reason for hiding this comment

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

It seems u r allowing the relative path here not rejecting it

Copy link
Author

Choose a reason for hiding this comment

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

  • The check for std::filesystem::path(filename).is_absolute() ensures that only absolute paths are accepted. Any relative paths (including those like ../..) are immediately rejected.

  • The use of std::filesystem::canonical() ensures that the path is properly resolved (eliminating any . or .. references), ensuring that it points to the correct file. Ex. path = "../npu.json" resolves to "absolute/path/to/npu.json" here if its a valid location else you throw a runtime exception while resolving path.

Copy link

Choose a reason for hiding this comment

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

But it should not be allowed. What if it is pointing to a file with no access to current user ?

Copy link

Choose a reason for hiding this comment

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

@vthaniel can you please test this scenario,

@sfatimar
Copy link

sfatimar commented Oct 4, 2024

Open Questions on Relative File Path access: To be tracked with a JIRA later

@sfatimar sfatimar merged commit 783b147 into ovep-develop-lnl-1.2 Oct 4, 2024
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.

2 participants