Scrivio Interview library
ScenarioIntermediate6 min read · updated 12 November 2026

A team moved from server-rendered Thymeleaf pages using sec:authorize to a React single-page application. How should the frontend decide which buttons to show, and what are the risks?

The server remains the authority, and the single-page application uses permissions only to decide what to display. The SPA should get them from the API, either from an endpoint such as GET /me/permissions that returns capabilities like invoice.approve rather than raw role names, or from allowed actions included in each resource response. The main risks are role names hard-coded in the frontend drifting from the server's rules and data hidden in the bundle on the assumption that the UI will never show it, so we test that every hidden action is also rejected by the API with 403.

Why this question is asked

With Thymeleaf, the server rendered only what the user was allowed to see, and sec:authorize did the hiding on the server. A React application is different: the whole bundle is downloaded to every user, and the browser decides what to render. Interviewers ask this scenario question to see whether we keep authorization on the server while still giving the frontend what it needs for a good experience. In this answer, we will look at what changed with the move, design a permissions endpoint, compare it with allowed actions in responses, discuss the drift and leakage risks, and finish with the tests that keep the API honest.

1What Changed With the Move to a SPA

In the server-rendered application, a hidden button never reached the browser, and its form posted to a URL protected by the filter chain. In a SPA, the JavaScript bundle contains every screen and every button for every kind of user. Hiding becomes a decision made by code running on the user's machine, which the user controls completely: they can open developer tools, change state and call any API directly.

So the principle is the same as before, only more visible. The API must enforce every rule, and the frontend's job is to avoid showing options that the API will refuse. A wrong display decision should cost usability, never security.

2Option 1: A Permissions Endpoint With Capabilities

The SPA asks the server once after login what the current user can do. The answer lists capabilities, names of actions such as invoice.approve, rather than roles such as FINANCE_MANAGER.

Java
@RestController
class MeController {
private final CapabilityPolicy policy; // the same rules the API uses
MeController(CapabilityPolicy policy) { this.policy = policy; }
@GetMapping("/api/me/permissions")
MePermissions permissions(Authentication auth) {
return new MePermissions(auth.getName(), policy.capabilitiesFor(auth));
}
record MePermissions(String user, Set<String> capabilities) {}
}
// GET /api/me/permissions as a finance manager
// {"user":"maria","capabilities":["invoice.read","invoice.approve","report.export"]}
// React
// {caps.has("invoice.approve") && <button onClick={approve}>Approve</button>}

Capabilities are the right vocabulary because the frontend wants to know what it may show, not who the user is. If the server later decides that team leads may also approve invoices, it changes its mapping, the endpoint returns invoice.approve for them, and the SPA needs no release. CapabilityPolicy should be built on the same mapping or authorization beans the API's @PreAuthorize rules use, so both answers come from one source.

3Option 2: Allowed Actions in Each Resource

Global capabilities do not cover object-level rules. A finance manager may approve invoice 42, which is pending, but not invoice 43, which is already paid or belongs to another region. For those cases, the resource response itself says what can be done with it.

Java
// GET /api/invoices/42
{
"id": 42, "status": "PENDING", "amount": 830.00,
"actions": { "approve": true, "cancel": true, "refund": false }
}
// Or in hypermedia style, with a link per allowed action
// "_links": { "self": {"href": "/api/invoices/42"},
// "approve": {"href": "/api/invoices/42/approve"} }
Ways a SPA can decide what to show
ApproachGood forRisk
Role names hard-coded in ReactNothing beyond a prototypeDrifts from server rules; needs releases
GET /me/permissions capabilitiesMenus, global featuresNo object state; cache refresh needed
Allowed actions per resourceButtons on a specific objectSlightly larger responses

The server computes each flag with the same authorization bean that protects the action, for example refundAccess.canRefund(auth, invoice). The frontend just renders buttons for true flags. This is the SPA version of the canRefund model attribute we would use in a Thymeleaf page, and it is the most accurate option because it accounts for the object's state as well as the user.

4The Risks: Drift and Leakage

The most common risk is drift. A frontend that checks user.roles.includes("FINANCE_MANAGER") has copied a server rule into JavaScript. When the server rule changes, the copy does not, so either buttons appear that fail with 403, or features disappear for people who are allowed to use them. Deriving capabilities and flags from the server's own policies removes the copy.

The more dangerous risk is leakage. Everything in the bundle and every API response is readable by the user, whatever the UI renders. Admin-only screens shipped in the bundle are fine as code, but secrets, API keys, internal URLs with embedded tokens, or data fields the user should not see must never be sent and merely hidden. If a response contains the salaries of a whole team and the React component shows only the user's own, the user has the salaries. The API must return only the data the user may see.

A smaller risk is staleness. Capabilities fetched at login can become outdated when an admin changes a role; refetching on focus or every few minutes, and always handling 403 gracefully, keeps the experience reasonable.

5Testing That Hidden Means Refused

Since the frontend's decisions are only cosmetic, we test the server for every action the UI hides: the API must reject the call with 403 (or 404 for objects the user should not know about).

Java
@Test
@WithMockUser(username = "tom", authorities = "invoice.read") // no invoice.approve
void approveIsRejectedForReaders() throws Exception {
mvc.perform(post("/api/invoices/42/approve").with(csrf()))
.andExpect(status().isForbidden()); // 403
}
@Test
@WithMockUser(username = "tom", authorities = "invoice.read")
void permissionsDoNotOfferApprove() throws Exception {
mvc.perform(get("/api/me/permissions"))
.andExpect(jsonPath("$.capabilities", not(hasItem("invoice.approve"))));
}

Pairing the two tests is the useful habit: one proves the UI will not offer the action, the other proves the API refuses it anyway. Together they show that display and enforcement agree, and the second one is the test that actually protects the data.

6Follow-up questions

Should the SPA receive the user's roles at all?

It can, for display such as a role badge, but authorization decisions in the frontend should use capabilities or per-resource flags. Roles in the frontend tend to become logic, which is where drift starts.

Where should tokens live in this setup?

Preferably not in the browser at all. A backend-for-frontend keeps the tokens on the server and gives the SPA a secure session cookie, which reduces the damage of a cross-site scripting bug. The permissions endpoint works the same way behind it.

Is hiding admin screens in the bundle a security problem?

Not by itself. Code is not a secret; an attacker learning that an admin screen exists gains little if every API behind it is protected. What must not be in the bundle are secrets and data.

7Conclusion

In this answer, we kept the server as the authority after moving from Thymeleaf to React. The SPA learns what to display from a /me/permissions endpoint returning capabilities, or from allowed actions included in each resource, both computed from the server's own policies. We discussed drift from hard-coded role names, leakage from data sent and merely hidden, and staleness, and we paired tests that check the UI's permissions with tests proving the API rejects the hidden actions with 403.

What to say in the interviewAbout 80 seconds aloud

Open with

The key principle is that the server stays the authority, and the SPA only uses permissions to decide what to show. Unlike Thymeleaf, the whole bundle reaches every user and they control the browser, so any API call can be made directly.

Then, if they want more

For global features and menus, I would expose an endpoint like GET /api/me/permissions that returns capabilities such as invoice.approve, computed from the same mapping or authorization beans the API uses in @PreAuthorize, rather than raw role names.

For buttons on a specific object, I would include allowed actions in the resource response, for example an actions object with approve true and refund false, or hypermedia links, because those depend on the object's state too. The risks are, first, drift: if React checks role names, those copies fall out of sync with the server rules; capabilities avoid that.

Second, leakage: never send secrets or data the user should not see and rely on the UI to hide them, because everything in the bundle or a response is readable. Third, staleness, so permissions are refreshed periodically and 403s are handled gracefully.

And I would test, for every hidden action, that the API itself returns 403 for a user without the capability.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Security reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A team moved from server-rendered Thymeleaf pages using sec:authorize to a React...": https://scrivio-interview-library.netlify.app/spring-boot/authorization/c57517dde3/