fix path traversal vulnerability in config loader#2
Merged
Conversation
Fix path traversal vulnerability in `Config::load_or_default` by canonicalizing and validating the config file path before reading. ## Changes - Canonicalize the input path to resolve symlinks and `..` components - Validate that the canonical path is within the expected config directory - Return an error if the path escapes the allowed boundary ## Why The original code read files directly from the provided path without validation. An attacker could manipulate the path using traversal sequences like `../../../etc/passwd` or symlinks to access sensitive files outside the intended config directory. Canonicalizing the path resolves these tricks to their true location, and the boundary check ensures only files within the config directory can be accessed. ## Semgrep Finding Details The application builds a file path from potentially untrusted data, which can lead to a path traversal vulnerability. An attacker can manipulate the path which the application uses to access files. If the application does not validate user input and sanitize file paths, sensitive files such as configuration or user data can be accessed, potentially creating or overwriting files. To prevent this vulnerability, validate and sanitize any input that is used to create references to file paths. Also, enforce strict file access controls. For example, choose privileges allowing public-facing applications to access only the required files. anthony@chovy.com requested this Autofix PR for [this finding](https://semgrep.dev/orgs/profullstack_inc/findings/791655676) from the detection rule [rust.actix.path-traversal.tainted-path.tainted-path](https://semgrep.dev/r/rust.actix.path-traversal.tainted-path.tainted-path).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix path traversal vulnerability in
Config::load_or_defaultby canonicalizing and validating the config file path before reading.Changes
..componentsWhy
The original code read files directly from the provided path without validation. An attacker could manipulate the path using traversal sequences like
../../../etc/passwdor symlinks to access sensitive files outside the intended config directory. Canonicalizing the path resolves these tricks to their true location, and the boundary check ensures only files within the config directory can be accessed.Semgrep Finding Details
The application builds a file path from potentially untrusted data, which can lead to a path traversal vulnerability. An attacker can manipulate the path which the application uses to access files. If the application does not validate user input and sanitize file paths, sensitive files such as configuration or user data can be accessed, potentially creating or overwriting files. To prevent this vulnerability, validate and sanitize any input that is used to create references to file paths. Also, enforce strict file access controls. For example, choose privileges allowing public-facing applications to access only the required files.
anthony@chovy.com requested this Autofix PR for this finding from the detection rule rust.actix.path-traversal.tainted-path.tainted-path.