fix: allow uppercase folder names in nested deployment routes - #27
Conversation
NAME_RE was designed for the flat deployment structure where :chart and :deployment params are used directly in file paths. With the folder param present, resolveDeploymentDir uses the folder query string instead, and path traversal is already blocked by the '..' check. Relaxing NAME_RE on :deployment when folder param is present lets real-world paths like myapp/PROD work without sacrificing security. Also surface save errors in AlertUserView so silent 400 failures are visible to the user instead of being swallowed. Closes #26 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Preview environment failed to start. |
|
Warning Review limit reached
More reviews will be available in 16 minutes and 15 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses rolling per-developer review limits. Reviews become available again as older review attempts age out of the rolling limit window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe PR relaxes ChangesNAME_RE Bypass for Folder Param + Save Error Handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 3
🤖 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 `@server/routes/deployments.js`:
- Line 67: The path validation logic uses a condition that skips NAME_RE
validation when req.query.folder is present, creating a path traversal
vulnerability where unsafe deployment segments with encoded slashes or parent
directory references can target files outside the intended directory. Remove the
negation of req.query.folder from the validation condition at lines 67, 86, 110,
and 129 so that NAME_RE.test(req.params.deployment) is always enforced
regardless of folder mode, ensuring the deployment parameter is always validated
against the safe name pattern before being used in path.join operations.
In `@src/pages/AlertUserView.jsx`:
- Around line 149-153: The handleSave function returns early when saveDeployment
fails but does not propagate this failure status to its callers like
handlePreview, which can cause callers to proceed with stale state after a
failed save. Modify the handleSave function to return a boolean or status
indicator (true for success, false for failure) that indicates whether the save
operation succeeded, and update all callers of handleSave to check this return
value before continuing with their respective flows.
In `@tests/integration/deployments-api.test.js`:
- Around line 209-219: The test currently only verifies the HTTP response status
(200) but does not confirm that the actual file deletion occurred on the
filesystem. After the DELETE request in this test, add an assertion that
verifies the target file at path.join(dir, 'PROD-values.yaml') has been deleted
and no longer exists. This ensures the test catches cases where the API returns
success without actually removing the file.
🪄 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 Plus
Run ID: e7a8f0a9-92a6-449f-83fe-fefd89d29416
📒 Files selected for processing (4)
server/routes/deployments.jsserver/routes/render.jssrc/pages/AlertUserView.jsxtests/integration/deployments-api.test.js
- deployments.js / render.js: replace blanket NAME_RE skip with FOLDER_DEPLOYMENT_SEGMENT_RE when folder param is present, blocking path traversal via '.' / '..' while still allowing uppercase names - AlertUserView: handleSave returns true/false; handlePreview aborts when save fails instead of rendering stale data - test: assert DELETE actually removes the file, not just HTTP 200 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Folder basenames like 'PROD' or 'STAGING' are valid deployment names but produce invalid Helm release names when uppercased. Lowercase and replace non-[a-z0-9-] chars so helm template succeeds regardless of folder case. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Cover the uppercase folder fix end-to-end: init a PROD deployment via API in beforeAll, then assert save shows "Saved at" timestamp and preview renders PrometheusRule YAML without an invalid release name error. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Root cause: Changes:
Tests: added 4 integration cases and 3 E2E cases covering uppercase folder save, preview, and rejection without the folder param. |
Summary
deployments.js/render.js: SkipNAME_REvalidation on:deploymentwhen?folderquery param is present. Security is already enforced by the..check inresolveDeploymentDir; the param is not used for path construction in the nested folder flow. This allows real-world folder basenames likePRODorSTAGINGthat would previously return 400.AlertUserView.jsx:handleSavenow checks the response fromsaveDeploymentand surfaces aSave failederror message instead of silently showing "Saved at ..." when the server returns an error.Test plan
folderparam is present; POST still rejects uppercase names withoutfolderparamKnown pre-existing failure (unrelated to this PR)
git-lib > runs a git command and returns stdoutzh_TW.UTF-8causesgit statusto output Chinese; test asserts English string'On branch'. Root cause is container-levelLC_ALLinjection that cannot be overridden via shell profile.Closes #26
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests