Skip to content
Book a call

Hiding the button is not access control

· 4-minute read · Engineering · by Direct Softworks

Our sidebar and buttons read the same policy table the server does. Their answers only decide what to hide. Keeping people out happens elsewhere, three times over.

Our management panel has eight roles, from owner through lawyer to developer, and each role holds view, manage or nothing on each module. The whole policy is one table in one file. The sidebar reads it. The command palette reads it. Every button that changes something is drawn only when the table says so.

None of those reads keeps anyone out. That is not an oversight. It is the design, and it is the part of access control that is easiest to get backwards.

An earlier post covered one failure: the action is gated and the page leaks the data anyway. This is the opposite half: the page is tidy, the button is hidden, and that proves nothing about the action behind it.

Why the browser may ask, and why its answer does not count

The policy file deliberately has no imports, so that client components can load it and ask the same questions the server asks, from the same table. That keeps the sidebar honest: nobody is shown a module they cannot open, or a button whose every press would be refused.

But a hidden button removes nothing from the server. In Next.js a server action is an HTTP endpoint, reachable by anyone who has its id. A route handler is a URL. "The interface does not offer it" has never been an access rule, and the answers the browser gets from the table are for hiding things, never for enforcing them.

Three doors, three guards

There are three independent ways into the panel, and a check on one of them does nothing for the other two.

Pages are guarded by each module's layout, which requires view before anything under it renders, including pages added later by someone who never thought about permissions. Server actions guard themselves, requiring manage on their module before they change anything. Route handlers inherit no layout at all, so each one calls the guard itself.

All three guards fail the same way: with a redirect. In Next.js a redirect is implemented by throwing, so a guard that refuses cannot return control to the code after it. The alternative, returning an error object, works only if every caller remembers to check it, and a caller that forgets to check a refusal carries on and does the thing.

A signed-in user who lacks a permission is not sent to the login screen either. That would tell them they are signed out, which is false, and it turns a permissions question into a support call about a broken login. They land on a screen they do have, with one sentence saying what happened.

The grep that cried wolf

Every actions file in the panel declares its own small helper called requireSession(), which simply calls the manage guard for that file's module. The name was kept on purpose, so that existing call sites did not have to change.

The side effect is that a search for requireSession across the codebase suggests every action only checks that somebody is signed in. That conclusion was drawn twice about the same module during reviews, and it was wrong both times. Read the helper's definition before you believe a guard is missing.

There is one deliberate exception. Changing your own password, revoking your own sessions and similar personal settings use the real signed-in check, not a module permission. Gate those on the settings module and most roles could never change their own password.

Forms are write surfaces with a URL

The subtler gap was in pages that are forms. A layout guard proves view. A page that creates a new invoice is a form that only makes sense with manage, and when we audited, only 3 of 16 such pages asked for it. A role that could read invoices could open the invoice builder, fill it in completely, and be refused on submit.

The data was never at risk; the action refused, as it should. The person's time was wasted, though, and a wall at the end of a form reads as a bug rather than as a permission. Every create and edit page now requires manage as its first statement, and the same audit stopped offering around twenty controls to roles whose every press would have been refused.

The check that does not accept a promise

The page-level half of this is enforced by a script that runs with the tests. It fails if a create or edit page does not require manage, and it fails if a page in a module some role can only view renders money or a link to a form without consulting the role first.

One detail in it is worth copying. A page may not satisfy the check with a variable named like a permission. An early draft accepted any may flag, and const mayCost = true passed, which is exactly the shape the regression takes. A check that accepts a promise in place of a question will be satisfied by the promise. The script was verified by reintroducing both defects on purpose and watching it fail.

The wider point

Hiding and refusing are two jobs. Hiding is courtesy: it keeps honest people from wasting their time. Refusing is security: it stops everyone else. They should read from the same table so they cannot disagree, and they must be enforced in different places, because the browser is the one part of the system you do not control.

More notes