Skip to content

fix: prevent path traversal in storage handler#689

Open
poyrazK wants to merge 3 commits into
mainfrom
fix/path-traversal-683
Open

fix: prevent path traversal in storage handler#689
poyrazK wants to merge 3 commits into
mainfrom
fix/path-traversal-683

Conversation

@poyrazK

@poyrazK poyrazK commented May 21, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add path traversal validation in getBucketAndKeyRequired helper
  • Reject keys containing .. pattern before reaching storage service
  • Protects all handlers: Upload, Download, Delete, InitiateMultipartUpload, ServePresignedDownload, ServePresignedUpload

Fixes

Fixes #683

Test plan

  • go build ./internal/handlers/...
  • go test ./internal/handlers/... -v

Reject keys containing '..' pattern to prevent path traversal
attacks (e.g., '../../etc/passwd'). All handlers using this
helper function are now protected.

Fixes #683
Copilot AI review requested due to automatic review settings May 21, 2026 10:42
@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@poyrazK has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 33 minutes and 6 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b9b1dff4-9fc3-489a-ba72-a104c2303693

📥 Commits

Reviewing files that changed from the base of the PR and between e0f151b and a71ebf5.

📒 Files selected for processing (2)
  • internal/handlers/helper.go
  • internal/handlers/helper_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/path-traversal-683

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

poyrazK added 2 commits May 21, 2026 13:49
- Check for path separators (/ and \) in addition to ".."
- Prevents encoded and mixed separator bypass attempts
- Add test case for path traversal rejection

Fixes #683
The Gin glob pattern *key captures paths with leading /, so
forward slashes in keys are normal. Revert to only checking
for ".." pattern while adding clarifying comment.

This fixes test failures in TestStorageHandlerUpload and other
storage handler tests that use keys like "test.txt".
Copilot AI review requested due to automatic review settings May 21, 2026 12:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/handlers bug Something isn't working size/xs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CRITICAL: Path traversal in storage handler - no key sanitization

2 participants