fix(api): enforce requireSuperUser on settings PATCH and fix dev-mode auth bypass #206
Reference in New Issue
Block a user
Delete Branch "fix/gro-263-dev-login-session-switch"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes two RBAC gaps found during UAT Scenario 5 testing:
isSuperUser: truefor all staff, which was bypassing RBAC checksChanges
Bug Fixes
apps/api/src/routes/settings.ts: AddedrequireSuperUser()middleware to PATCH routeapps/api/src/middleware/rbac.ts: Fixed 3 locations in dev mode that force-setisSuperUser: true— now preserves actual DB value with?? falsefallbackTests
apps/api/src/__tests__/rbac.test.ts: Fixed test data (RECEPTIONIST/GROOMER now correctly haveisSuperUser: false) and added 7 new tests forrequireSuperUsermiddlewareTest Plan
pnpm --filter api testpasses (197 tests)cc @cpfarhood
QA Review: Request Changes
The lint check is failing due to an unused variable:
CI Status:
app)The code changes for the fix look correct:
requireSuperUser()correctly added toPATCH /api/settingsmanager.isSuperUser ?? falseisSuperUser: falseOnce the lint error is fixed, please re-run CI or close/reopen the PR to trigger a fresh run.
Closing per GRO-311 to retrigger CI after lint fix
QA Review: Request Changes
The lint check is still failing:
The variable
appon line 292 was assigned after the test body was refactored but is no longer used — the actual assertion was moved to thetestAppblock above it. Remove the unusedappassignment on line 292.CI Status:
Once the lint error is fixed, please close/reopen the PR to trigger a fresh CI run (note: CI bot pushes don't retrigger CI — engineering must manually retrigger).
QA Review: Request Changes
The lint check is still failing:
The variable
appon line 292 was assigned after the test body was refactored but is no longer used — the actual assertion was moved to thetestAppblock above it. Remove the unusedappassignment on line 292.CI Status:
Once the lint error is fixed, please close/reopen the PR to trigger a fresh CI run (note: CI bot pushes do not retrigger CI — engineering must manually retrigger).
Deployed to groombook-dev
Images:
pr-206URL: https://dev.groombook.farh.net
Ready for UAT validation.
Deployed to groombook-dev
Images:
pr-206URL: https://dev.groombook.farh.net
Ready for UAT validation.
QA Verification: All CI checks passing
UAT Scenario 5 fix verified via CI. Approving for CTO review.
CTO Review: Changes Requested — Scope Issue
The RBAC fix itself is correct and well-tested. However, this PR bundles two unrelated pieces of work that must be separated.
GRO-384 (in scope) ✅
requireSuperUser()added toPATCH /api/admin/settingsisSuperUser: truebypass fixed (3 locations inrbac.ts)requireSuperUsermiddlewareisSuperUser: falsefor RECEPTIONIST/GROOMER)GRO-387 (out of scope — remove from this PR) ❌
auth_provider_configtable + migration (0021_classy_hedge_knight.sql)packages/db/src/crypto.ts(AES-256-GCM encryption helpers)apps/api/src/__tests__/crypto.test.tspackages/db/src/schema.ts(new table definition)packages/db/src/index.ts(new export)packages/db/migrations/meta/*(snapshot)What to do
0ca63f2) from this branch (rebase or revert)The RBAC fix is security-relevant and must be isolatable in git history. Do not bundle unrelated schema migrations with security fixes.
Deployed to groombook-dev
Images:
pr-206URL: https://dev.groombook.farh.net
Ready for UAT validation.
Deployed to groombook-dev
Images:
pr-206URL: https://dev.groombook.farh.net
Ready for UAT validation.
QA Re-Approval — GRO-384 RBAC Fix
PR #206 re-reviewed after force-push rebase.
Diff confirmed unchanged from prior approval — same 2 commits (
804bb47+01b090f) with GRO-387 cleanly removed via rebase.CI Status (commit
01b090f):Changes verified:
requireSuperUser()applied toPATCH /api/admin/settingsisSuperUser: row.isSuperUser ?? false) in 3resolveStaffMiddlewarelocationsisSuperUser: falsefor RECEPTIONIST/GROOMER)requireSuperUsermiddlewareApproval: QA APPROVED
Ready for CTO final review and merge.
CTO Approval
RBAC fix is correct and well-scoped after rebase:
All CI green. Approved for merge.