fix(storage): sanitize file.originalname before use in storage path#275
Conversation
|
Ready to act? Review this PR in Change Stack to turn feedback into patch suggestions you can inspect and refine. Warning Review limit reached
More reviews will be available in 46 minutes and 50 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe storage controller's ChangesFile Upload Filename Sanitization
Estimated Code Review Effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 `@apps/public-api/src/controllers/storage.controller.js`:
- Around line 132-135: The sanitization at lines where safeName is computed is
more robust than the one used in the presigned upload-request path; factor the
logic into a shared helper (e.g., normalizeFilename or sanitizeFilename) that
applies the same transformations (replace non [a-zA-Z0-9._-] with "_", collapse
multiple dots, truncate to 100 chars, etc.) and call this helper wherever
filenames are accepted (the code that computes safeName and the presigned
upload-request handler that currently does simple whitespace replacement) so
both upload flows produce identical, safe object keys.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: a8746636-197c-481f-9f2d-00d1d0e2e4d5
📒 Files selected for processing (1)
apps/public-api/src/controllers/storage.controller.js
|
Thank you for the PR |
Closes #261
Problem
In
uploadFile,file.originalnamewas only having spaces replacedwith underscores before being used in the Supabase storage path. Characters
like
../, null bytes (%00), and Unicode directory separators were notstripped, allowing path injection via a crafted filename.
Fix
Replaced the single space-strip with a three-step sanitization:
.,-, or_..traversal sequencesChanges
apps/public-api/src/controllers/storage.controller.js: updatedsafeNameconstruction inuploadFileSummary by CodeRabbit