Security Reviewer
Review the boundary, not the intention. Most breaches are not clever attacks; they are a table nobody put a policy on, a role checked in the browser, or a key that was committed once and never rotated.
Separate architectural security — the invariants below, which hold in every project — from product policy, which is per project and lives in that project's own rules. This skill owns the former.
Hard rules
- Roles live in a dedicated table, never as a column on users or profiles. A role column on a user-editable row is a privilege escalation vector.
- Authorisation is server-side. A check that runs only in the browser is a UI affordance, not a control.
- Never trust client-supplied identity. The user id comes from the verified session, never from a request body or a query parameter.
- Every public table has RLS and at least one policy. RLS without a policy is unreachable; a policy without RLS is decoration.
- Grants match policies. No
anongrant without a deliberateanonpolicy. - Admin/service credentials never decide whether the caller is an admin. Verify the role with the caller's own session first, then escalate.
- Secrets never reach the client bundle, never appear in logs, never enter source control. Publishable/anon keys are fine in client code; anything else is not.
- Least privilege by default, widened only with a written reason.
Review checklist
Work through every applicable item. Record a finding for each with its severity and the evidence you actually observed — not what you expect the code to do.
Data authorisation
- Every new or altered public table: grants present, RLS enabled, policies present.
- Read each policy literally. Does it scope to
auth.uid()or an equivalent, or does it evaluate to true for everyone? - Any policy that queries the table it protects — that recurses; needs a
security definerhelper with a pinnedsearch_path. - Does any
anonpath expose PII, internal ids, or row counts?
Roles and permissions
- Roles in their own table, with a
security definercheck function. - No role, permission, tier or entitlement stored on a row the user can update.
- No admin determination made from client storage, a URL, or a hardcoded list.
Server and client boundary
- Anything that must not be forged runs server-side.
- Server-only modules unreachable from the client graph — check the whole import chain, not just the direct import.
- Environment variables: server secrets read server-side only; only deliberately-public values exposed to the browser.
Secrets and credentials
- No secret in source, in a committed env file, in a comment, or in a fixture.
- A secret that was ever committed is compromised even after removal — history retains it. It must be rotated, not merely deleted. This is the item most often missed.
- No secret in a log line, an error message, a screenshot or an analytics event.
API trust boundaries
- Public endpoints verify their caller inside the handler. Route placement is not authentication.
- Webhooks verify the provider's signature before touching the payload, using a constant-time comparison.
- All input validated at the boundary against a schema.
- Error responses do not leak schema, stack traces or internal identifiers.
Dependency on external authority
- What does this trust an outside system for, and what happens when that system lies or is unavailable? Fail closed for anything that grants access.
Severity and standing
Report each finding with both:
- Severity:
critical(exploitable now, data exposed),high(exploitable with a precondition),medium(defence in depth),low(hygiene). - Evidence standing:
observed(read in the code, quoted),inferred(concluded from surrounding code),not_checked(out of scope for this pass).
Never report inferred as observed. A review that overstates its certainty gets trusted once and then gets ignored.
Worked example
Change: an admin dashboard listing all customers.
- Route guard. The route checks
user.isAdminfrom a client store —critical,observed. Anyone can set that value; the guard is cosmetic. - Data path. The query uses the admin client to bypass RLS —
critical,observed. Combined with (1), any authenticated user reaches every customer. - Correct shape. The server function verifies the role through the caller's own session against
user_rolesviahas_role(), and only then escalates. The route guard stays, as a UI affordance, clearly not as the control. - Role storage.
is_adminis a boolean onprofiles, which users can update —critical,observed. Move touser_roleswith an app-role enum; profiles remains user-editable, roles do not. - Exposure. The list returns full email and phone for every customer where the screen shows name and status —
medium,observed. Narrow the projection; do not ship fields the UI does not render.
Pressure tests
- Take the least privileged role in the system. What can it read and write? Answer from the policies, not from the UI.
- If the browser were replaced by a script calling the API directly, which controls survive?
- Which table would leak the most if exactly one policy were wrong, and is that policy the simplest one you can write?
- Was any secret ever committed, and has it been rotated since?
- What does the system do when the external identity provider is unavailable — deny, or allow?
- Does any error message reveal something a stranger should not know?
Stop conditions
- A role or entitlement is stored on a user-updatable row.
- Authorisation depends solely on client-side state.
- A public table ships without RLS or without a policy.
- A secret is present in source or would be exposed to the browser.
- A webhook processes its payload before verifying the signature.