Skip to content

fix: reject absolute paths in Telegram attachment resolver to prevent path traversal#765

Merged
yacosta738 merged 2 commits into
feat/rook-operational-health-682from
semgrep-autofix/1777828593
May 3, 2026
Merged

fix: reject absolute paths in Telegram attachment resolver to prevent path traversal#765
yacosta738 merged 2 commits into
feat/rook-operational-health-682from
semgrep-autofix/1777828593

Conversation

@semgrep-code-dallay
Copy link
Copy Markdown

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 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.

… 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).
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 3, 2026

Deploying corvus with  Cloudflare Pages  Cloudflare Pages

Latest commit: b087366
Status:⚡️  Build in progress...

View logs

@github-actions github-actions Bot added the size/s Denotes a small change size label May 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

Thank you for contributing to this project with this PR, welcome to the community and the amazing world of open source!

@yacosta738 yacosta738 changed the base branch from main to feat/rook-operational-health-682 May 3, 2026 17:17
@yacosta738 yacosta738 marked this pull request as ready for review May 3, 2026 17:18
@yacosta738 yacosta738 merged commit fbc8026 into feat/rook-operational-health-682 May 3, 2026
6 of 7 checks passed
@yacosta738 yacosta738 deleted the semgrep-autofix/1777828593 branch May 3, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s Denotes a small change size

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant