Invental/Review lessons/Trust boundaries the server must hold

Trust boundaries the server must hold

A disabled toggle is not a permission

A disabled switch is not a permission rule: re-check the invariant in the server action. And revoke tokens based on what changed (old grant vs new), not just on what the new grant lacks.

01 · Before and afterThe pattern

TypeScript
// before: subset check only
if (selected.some((s) => !grant.scopes.includes(s))) throw new Error("re-consent");
// after: enforce the UI's invariants server-side, and revoke on a real transition
if (!selected.length || (grant.scopes.includes("read") && !selected.includes("read")))
  throw new Error("Keep read access, or disconnect");
const droppedOffline = grant.scopes.includes("offline_access") && !selected.includes("offline_access");
if (droppedOffline) await db.refreshToken.deleteMany({ where: { userId, clientId } });

02 · Run it on your appThe check

For every toggle your UI disables, does the server action reject that same change if called directly?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.