Skip to content

fix: allow uppercase folder names in nested deployment routes - #27

Merged
HahaSula merged 4 commits into
mainfrom
fix/name-re-nested-deployment
Jun 23, 2026
Merged

fix: allow uppercase folder names in nested deployment routes#27
HahaSula merged 4 commits into
mainfrom
fix/name-re-nested-deployment

Conversation

@HahaSula

@HahaSula HahaSula commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • deployments.js / render.js: Skip NAME_RE validation on :deployment when ?folder query param is present. Security is already enforced by the .. check in resolveDeploymentDir; the param is not used for path construction in the nested folder flow. This allows real-world folder basenames like PROD or STAGING that would previously return 400.
  • AlertUserView.jsx: handleSave now checks the response from saveDeployment and surfaces a Save failed error message instead of silently showing "Saved at ..." when the server returns an error.

Test plan

  • Added 4 integration tests covering: GET / POST / DELETE accept uppercase deployment names when folder param is present; POST still rejects uppercase names without folder param
  • 175/176 tests pass

Known pre-existing failure (unrelated to this PR)

Test Cause
git-lib > runs a git command and returns stdout System locale zh_TW.UTF-8 causes git status to output Chinese; test asserts English string 'On branch'. Root cause is container-level LC_ALL injection that cannot be overridden via shell profile.

Closes #26

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Deployment save operations now display error messages when they fail.
  • Tests

    • Added integration tests for deployment API validation scenarios.

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>
@rophy

rophy commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

PR Preview Bot

Preview environment failed to start.

...(truncated)
#20 [app stage-1 10/10] COPY index.html ./
#20 CACHED

#21 [app] exporting to docker image format
#21 exporting layers done
#21 exporting manifest sha256:c06c49f52dbbeff29652f7379661c3a3dd2c0730086621df614274cdbf45a4d3 done
#21 exporting config sha256:e454eaecc1aa53d7a7a13c3dd997e09a5ec6078de0cff5f71c54cc1880bef1ec done
#21 sending tarball
#21 sending tarball 1.2s done
#21 DONE 1.2s

#22 [app] importing to docker
#22 DONE 0.0s

#23 [app] resolving provenance for metadata file
#23 DONE 0.0s
 app  Built
 Container null-ptr-exception-rulemgmt-pr-27-app-1  Starting
Error response from daemon: failed to set up container networking: driver failed programming external connectivity on endpoint null-ptr-exception-rulemgmt-pr-27-app-1 (2ecccb14ec254dde8d6b51bfd87a40bf974dd1f6f1629a7ff8f198ade2ace903): Bind for 127.0.0.1:12101 failed: port is already allocated

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@HahaSula, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 995901ea-3216-4cab-92ab-76129605a979

📥 Commits

Reviewing files that changed from the base of the PR and between 78657d6 and bfc228c.

📒 Files selected for processing (5)
  • server/routes/deployments.js
  • server/routes/render.js
  • src/pages/AlertUserView.jsx
  • tests/e2e/nested-deployment.spec.js
  • tests/integration/deployments-api.test.js
📝 Walkthrough

Walkthrough

The PR relaxes NAME_RE deployment-name validation in deployments.js and render.js so the check is skipped when ?folder= is present in the query. AlertUserView.jsx gains error handling in handleSave to surface failures. Integration tests verify the new conditional behavior.

Changes

NAME_RE Bypass for Folder Param + Save Error Handling

Layer / File(s) Summary
Conditional NAME_RE validation in deployment and render routes
server/routes/deployments.js, server/routes/render.js
GET/POST/DELETE endpoints in deployments.js and the POST handler in render.js now skip NAME_RE validation on req.params.deployment when req.query.folder is present; chart validation is unchanged.
AlertUserView save-failure error handling
src/pages/AlertUserView.jsx
handleSave captures the saveDeployment return value, shows message.error('Save failed'), and returns early when result.ok is falsy, preventing silent success on server errors.
Integration tests for folder-param name validation
tests/integration/deployments-api.test.js
New describe block with isolated temp directory and folderQuery() helper; four tests assert uppercase deployment names pass GET/POST/DELETE with ?folder= and fail with 400 on POST without it.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hoppity-hop through the folder path I go,
PROD and STAGING need not fear NAME_RE's veto,
When ?folder= arrives, the gate swings wide,
But sans that param, the old rules still abide.
And if a save should falter — no more silent woe,
The bunny rings the bell so every user knows! 🔔

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly reflects the main change: allowing uppercase folder names in nested deployment routes by relaxing NAME_RE validation when folder parameter is present.
Linked Issues check ✅ Passed The PR fully addresses #26 requirements: deployments.js and render.js skip NAME_RE validation when folder parameter is present, and AlertUserView.jsx now surfaces save errors instead of silently failing.
Out of Scope Changes check ✅ Passed All changes are directly scoped to #26: validation logic modifications in deployments.js and render.js, error handling in AlertUserView.jsx, and integration tests for the new folder parameter behavior.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/name-re-nested-deployment

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.

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 29b151c and 78657d6.

📒 Files selected for processing (4)
  • server/routes/deployments.js
  • server/routes/render.js
  • src/pages/AlertUserView.jsx
  • tests/integration/deployments-api.test.js

Comment thread server/routes/deployments.js Outdated
Comment thread src/pages/AlertUserView.jsx
Comment thread tests/integration/deployments-api.test.js
HahaSula and others added 3 commits June 23, 2026 14:25
- 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>
@HahaSula

Copy link
Copy Markdown
Contributor Author

Root cause: NAME_RE was designed for the flat deployment structure. When nested folder support (?folder=) was added, the :deployment param validation was never relaxed — causing uppercase folder names (e.g. TEST, PROD) to always return 400 and silently fail on save.

Changes:

  • deployments.js / render.js: when ?folder= is present, switch to FOLDER_DEPLOYMENT_SEGMENT_RE (allows uppercase, blocks .. / / / \); NAME_RE still applies without folder
  • render.js: normalize Helm release name to lowercase to avoid invalid release name error
  • AlertUserView.jsx: handleSave now returns true/false; handlePreview aborts if save fails instead of silently proceeding

Tests: added 4 integration cases and 3 E2E cases covering uppercase folder save, preview, and rejection without the folder param.

@HahaSula
HahaSula merged commit 5d9f1de into main Jun 23, 2026
4 checks passed
@HahaSula
HahaSula deleted the fix/name-re-nested-deployment branch June 23, 2026 09:30
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.

fix: NAME_RE validation blocks nested deployment folders with uppercase names

2 participants