fix: reject absolute paths in Telegram attachment resolver to prevent path traversal#765
Merged
yacosta738 merged 2 commits intoMay 3, 2026
Conversation
… path traversal Fix path traversal vulnerability in Telegram attachment path resolution by rejecting absolute paths. ## Changes - Added explicit validation to reject absolute paths in `resolve_attachment_path` - All attachment paths must now be relative to the configured attachment root - Removed conditional logic that allowed absolute paths to bypass the root directory join ## Why The previous implementation allowed absolute paths to be used directly as candidates, which could potentially allow path traversal attacks. Although there was a `starts_with` check after canonicalization, rejecting absolute paths early provides defense-in-depth and makes the security boundary explicit. By requiring all paths to be relative, we ensure they are always resolved within the attachment root directory. ## 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. Semgrep generated this pull request to fix [a finding](https://semgrep.dev/orgs/yap/findings/772954974) from the detection rule [rust.actix.path-traversal.tainted-path.tainted-path](https://semgrep.dev/r/rust.actix.path-traversal.tainted-path.tainted-path).
Contributor
|
Thank you for contributing to this project with this PR, welcome to the community and the amazing world of open source! |
fbc8026
into
feat/rook-operational-health-682
6 of 7 checks passed
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 Telegram attachment path resolution by rejecting absolute paths.
Changes
resolve_attachment_pathWhy
The previous implementation allowed absolute paths to be used directly as candidates, which could potentially allow path traversal attacks. Although there was a
starts_withcheck after canonicalization, rejecting absolute paths early provides defense-in-depth and makes the security boundary explicit. By requiring all paths to be relative, we ensure they are always resolved within the attachment root directory.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.
Semgrep generated this pull request to fix a finding from the detection rule rust.actix.path-traversal.tainted-path.tainted-path.