Use filepath.Base when transfering backups#199
Conversation
📝 WalkthroughWalkthrough
ChangesBackup filename sanitization
Estimated code review effort: 1 (Trivial) | ~3 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 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)
| backupNameUnsafe := strings.TrimPrefix(name, "backup_") | ||
| // Strip all directory components | ||
| backupName := filepath.Base(backupNameUnsafe) |
There was a problem hiding this comment.
🗄️ 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.
Changes
Summary by CodeRabbit