Skip to content

Use filepath.Base when transfering backups#199

Merged
QuintenQVD0 merged 1 commit into
mainfrom
transfer-backup-name
Jul 13, 2026
Merged

Use filepath.Base when transfering backups#199
QuintenQVD0 merged 1 commit into
mainfrom
transfer-backup-name

Conversation

@QuintenQVD0

@QuintenQVD0 QuintenQVD0 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Changes

  • Validate that the backupname is within the base path when transfering backups

Summary by CodeRabbit

  • Bug Fixes
    • Improved backup file handling by removing directory components from uploaded filenames.
    • Ensured backup storage and checksum verification use the sanitized filename.

@QuintenQVD0
QuintenQVD0 requested a review from a team as a code owner July 13, 2026 18:17
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

postTransfers now strips directory components from multipart backup filenames before using them for storage and checksum verification.

Changes

Backup filename sanitization

Layer / File(s) Summary
Sanitize multipart backup name
router/router_transfer.go
The backup filename is trimmed and reduced to its base path component before file writing and checksum keying.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Suggested reviewers: huwutao, parkervcp, matthewpi, daneeveritt, iamkubi

Poem

A bunny trims the paths away,
So backups safely hop and stay.
No hidden burrows in the name,
Just tidy files for checksum fame.
Hop, hop—securely saved today!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: using filepath.Base during backup transfer handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch transfer-backup-name

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.

@parkervcp parkervcp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@router/router_transfer.go`:
- Around line 266-268: Validate the raw suffix in the backup-name handling
before creating any file: when backupNameUnsafe differs from
filepath.Base(backupNameUnsafe), including "." or "..", reject the multipart
part instead of using the collapsed basename. Keep accepted names unchanged and
ensure rejection occurs before destination creation and checksum processing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a7704310-d1d3-4954-8684-9da71677e008

📥 Commits

Reviewing files that changed from the base of the PR and between 1c2070e and b97d776.

📒 Files selected for processing (1)
  • router/router_transfer.go
📜 Review details
⏰ Context from checks skipped due to timeout. (3)
  • GitHub Check: Build and Test (ubuntu-22.04, 1.25.11, linux, amd64)
  • GitHub Check: Build and Test (ubuntu-22.04, 1.26.4, linux, amd64)
  • GitHub Check: Analyze (go)

Comment thread router/router_transfer.go
Comment on lines +266 to +268
backupNameUnsafe := strings.TrimPrefix(name, "backup_")
// Strip all directory components
backupName := filepath.Base(backupNameUnsafe)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Reject path-bearing backup names instead of silently collapsing them.

filepath.Base prevents directory traversal, but it also maps distinct multipart names such as backup_a/foo.tar.gz and backup_b/foo.tar.gz to the same destination; the later part can truncate the earlier file. Checksum fields are still keyed from the raw suffix at Lines 308-317, so the filename and checksum contracts can also diverge.

Reject names where backupNameUnsafe != filepath.Base(backupNameUnsafe) (including . and ..) before creating the file, or canonicalize checksum names identically and reject duplicate normalized names.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@router/router_transfer.go` around lines 266 - 268, Validate the raw suffix in
the backup-name handling before creating any file: when backupNameUnsafe differs
from filepath.Base(backupNameUnsafe), including "." or "..", reject the
multipart part instead of using the collapsed basename. Keep accepted names
unchanged and ensure rejection occurs before destination creation and checksum
processing.

@QuintenQVD0
QuintenQVD0 merged commit 70f3344 into main Jul 13, 2026
7 checks passed
@QuintenQVD0
QuintenQVD0 deleted the transfer-backup-name branch July 13, 2026 18:22
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.

2 participants