← All posts

A hidden button is not a permission

A hidden button is not a permission

Here is a test worth running on any business application you are evaluating. Log in as a user who is not allowed to approve invoices. Open the browser's developer tools, find the request the approve button would have sent for someone who is allowed, and send it yourself.

In a surprising amount of software, it works. The button was hidden, so everyone assumed the action was protected. But hiding is something the screen does, and the screen runs on the user's own computer. The endpoint behind the button never checked anything, because the front-end developer and the back-end developer each thought the other one had.

TSQL.APP removes the place where that misunderstanding can happen: there is no front-end permission to forget. Every check is made in the database, by the same procedures that build the screen.

Three questions, all answered in SQL

Access in a TSQL.APP application comes down to three questions. Who may open this screen? Who may press this button? Which records may this person see?

All three are answered from metadata — rows in the framework's own tables — and all three are enforced in SQL Server before anything is sent to the browser.

Screens and buttons carry roles. A card (the framework's word for a screen) and each button on it have a role column. Leave it empty and everyone who can log in may use it; fill it in and only users with one of those roles may. The user's roles come from the signed login token and are held for the duration of the request; nothing the user can edit in a request changes them.

Records carry a predicate. A card can have a read condition: an ordinary T-SQL boolean expression, evaluated against each row of the table behind the screen. For a customer list where account managers see their own accounts and the sales manager sees everything:

sql
account_manager_id = @user_id OR dbo.hasRole('sales_manager') > 0

That is the entire rule. @user_id is filled in by the framework from the logged-in user, not from the request, and dbo.hasRole checks the roles of the current session.

The rule is part of the query

Where that expression ends up is the part worth understanding.

A card does not have a hand-written query. The framework generates the SQL for the list and the detail view from the card's metadata — and the read condition is AND-ed into the WHERE clause of that generated SQL. Not checked afterwards. Not filtered in the browser. Part of the query itself.

So a row outside the condition is never selected and never sent. Typing its id into the address bar asks the detail view for a row whose WHERE clause includes the same condition — and gets nothing back. There is no second code path that fetches records "the other way" and forgot the rule.

The part that surprises people

Now go back to the test at the top: the forged request for a button the user does not have.

A button's role is checked twice, both times on the server. The first check happens when the menu is built — the button is filtered out with the same role test, so it is never drawn. The second happens when a click arrives. The framework does not take the button's code from the request; it looks the button up again, by name, from the card's buttons for this user. That lookup is filtered by role exactly as the menu was.

So the forged request finds no matching row. There is no code to run. The request ends — at most the user sees a polite "Nothing to do here".

Note what did not happen. There was no "access denied", because nothing was denied. To this user, the button does not exist; asking for it is like asking for a button that was never built. That is a stronger property than a permission check, because there is no branch of code where the check could be missing. The thing that finds the button and the thing that authorises it are the same SELECT.

"So every developer has to remember to add the check?"

That is the right question to ask of any permission model, and here the answer is no.

The role tests live in the framework procedures that build menus, generate the list and detail SQL, and look up buttons. A new card or a new button goes through the same procedures as every other one, so it gets the same checks without anyone writing them. The developer decides what the rule is — which role, which condition. They do not decide whether it is enforced, and they cannot forget to.

What it does not do is choose the rules for you. An empty role column means "everyone who can log in", and that is a decision too. A read condition that is too generous is enforced just as faithfully as a correct one. The framework guarantees that the rule you wrote is the rule that runs, everywhere. Writing the right rule is still your job.

It is also worth being clear about whom this model is for. Roles govern the people who use the application. Those users have no SQL access of any kind; everything they can do reaches the database through the screens and buttons described above. Administrators, and anyone who has direct access to the database itself, are outside it by design. At that level everything is visible, as it is in any database, and protecting that access is the job of SQL Server's own security.

Inside your own scripts

Inside an action script the same functions are available directly, for the cases the metadata does not cover — a button everyone may press, but whose last step only a manager may confirm:

sql
IF dbo.hasRole('finance_manager') = 0
BEGIN
    RAISERROR('Not allowed|Only a finance manager can release this payment.', 11, 1);
    RETURN;
END

Severity 11 is the framework's way of saying "show the user an error and stop": the text before the | becomes the heading of the dialog, the rest becomes its body. The check runs in the database, against the session's roles, inside the same request as the work it protects.

Where to go next

Roles and record conditions are set per card and per button. The documentation and the programming reference cover the cards, the buttons and the helpers around them. And if you would like to see it on a live application, book a demo — bring the forged-request test with you.