Harden role & permission authorization boundaries; add RLS migration and tests - #15
Harden role & permission authorization boundaries; add RLS migration and tests#15ethandemouradev wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 60411f749b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const { data: targetRoleRow } = await routeServiceClient.from("user_roles").select("role").eq("user_id", id).maybeSingle(); | ||
| const targetRole = String(targetRoleRow?.role ?? "member").toLowerCase(); |
There was a problem hiding this comment.
Fail closed when the target role lookup errors
If the user_roles lookup fails, this silently treats the target as a rank-10 member; a staff actor with permissions.grant can therefore pass the hierarchy check for an administrator or other stronger target whenever this read errors but subsequent writes succeed. Inspect the Supabase error and reject the request instead of applying the member fallback on query failure.
Useful? React with 👍 / 👎.
Motivation
Description
canManagePermissionSetandcanManageRoleinsrc/lib/staff/userAccess.tsto refuse self-edits, equal/higher-target edits, granting unknown keys, and granting permissions the actor does not hold.src/app/api/staff/security/users/[id]/permissions/route.ts,src/app/api/staff/security/roles/route.ts, andsrc/app/api/staff/security/roles/[key]/permissions/route.ts.supabase/migrations/20260811030000_security_boundary_hardening.sql(with rollback) that tightensprofilesSELECT to owner-or-staff, removes browserSELECTon baseroles/permissions, and revokesTRUNCATEfromservice_roleon several sensitive tables, and explicitly mark itMIGRATION APPROVAL REQUIRED(do not apply without review).docs/SECURITY_HARDENING.mddocumenting the authorization matrix, findings, migration packet, and residual risks.tests/security-hardening.test.tsexercising limited-staff escalation, unknown permissions, self-overrides, stronger targets, role-rank escalation, and the owner exemption.Testing
node --experimental-strip-types --test tests/security-hardening.test.tsand all 5 tests passed.npm run typecheck(TypeScripttsc --noEmit) and resolved issues introduced by changes; typecheck passed for the modified code.npm test/ full repository test andnpm run buildexposed unrelated baseline environment and module-resolution issues (missingNEXT_PUBLIC_SUPABASE_URL, extension/alias resolution under the local Node environment) and many preexisting lint warnings/errors; these are documented indocs/SECURITY_HARDENING.mdand do not block the focused hardening verification above.MIGRATION NOTE: The SQL migration was created and committed but NOT APPLIED; it is explicitly marked
MIGRATION APPROVAL REQUIREDbecause replacing the openprofilespolicy can affect public/community pages and must be staged and approved before applying to production.Codex Task