Skip to content

fix path traversal vulnerability in config loader#2

Merged
ralyodio merged 1 commit into
masterfrom
semgrep-autofix/1778672796
May 13, 2026
Merged

fix path traversal vulnerability in config loader#2
ralyodio merged 1 commit into
masterfrom
semgrep-autofix/1778672796

Conversation

@semgrep-code-profullstack
Copy link
Copy Markdown
Contributor

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 from the detection rule rust.actix.path-traversal.tainted-path.tainted-path.


⚠️ Review carefully before merging. This PR was generated by AI and may cause breaking changes or introduce new vulnerabilities.

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).
@ralyodio ralyodio marked this pull request as ready for review May 13, 2026 13:43
@ralyodio ralyodio merged commit 23827ca into master May 13, 2026
7 of 8 checks passed
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.

1 participant