Distinguish browser and server trust
The browser is not an authority
A trust boundary separates data or operations controlled by different actors. In a React application, the browser belongs to the visitor: props, state, hidden buttons and requests cannot establish permission. A server must identify the caller using a validated session and authorize each operation on the requested resource. Authentication answers who the caller is; authorization answers whether that caller may act. In this chapter a fictional lending desk displays equipment requests. The server model uses synthetic identities only; there are no real accounts or network requests.
import React from 'react';export default function RequestCard({request, canCancel, onCancel}) { return <article><h2>{request.title}</h2><p>{request.status}</p> {canCancel && <button type="button" onClick={() => onCancel(request.id)}>Cancel request</button>} </article>;}With canCancel true, an authorized visitor sees a cancel button; with false, the button is absent. This is a usability feature, not a security control. The caller must handle a server rejection even if the UI previously displayed permission, because the session or request status may have changed. Never send private records and simply hide them with CSS.
Check the operation at the server boundary
export function cancelDecision(principal, record) { if (!principal || typeof principal.id !== 'string' || !principal.id) return 401; if (!record || record.ownerId !== principal.id) return 404; if (record.status !== 'pending') return 409; return 200;}export function publicRequest(record) { return {id: record.id, title: record.title, status: record.status};}The function assumes principal is already authenticated by trusted server middleware, and record is loaded from trusted storage using a validated identifier. A missing session returns 401; missing or other-owner records both return 404 to avoid directly exposing existence; a non-pending owned record returns 409. A pending owned record yields 200, which means permission in this toy model only. The real server must perform authorization and the status change atomically, validate input, handle concurrency and return only permitted fields. The projection deliberately omits ownerId and private notes. It is not a complete API implementation.
Separate browser policy from server permission
The same-origin policy limits script access between origins (scheme, host and port). CORS allows selected cross-origin reads via response headers; it is not authentication or authorization and does not prevent all cross-origin requests. CSRF is an unwanted authenticated action, often involving automatically attached cookies. Use framework-supported CSRF protection for state-changing requests, appropriate SameSite cookies and origin checks as additional layers. Never use GET for state changes. A Secure cookie requires secure transport in ordinary deployments; HttpOnly prevents ordinary script reads, not authenticated requests made by script. SameSite is site-based rather than origin-based. Cookie choices depend on login flow and domain architecture.
export async function cancelRequest(id, csrfToken, request = fetch) { if (typeof id !== 'string' || !/^[a-z0-9-]{1,40}$/.test(id)) throw new Error('Invalid request ID'); const response = await request('/api/requests/' + encodeURIComponent(id) + '/cancel', { method: 'POST', credentials: 'same-origin', headers: {'X-CSRF-Token': csrfToken} }); if (!response.ok) return {ok:false, status:response.status}; return {ok:true};}This is a partial client contract for a server that issues and validates session-bound CSRF tokens. The token is not an authorization credential and must not be logged. The default fetch is for a future approved same-origin deployment; local tests pass a fake request function. CORS is unnecessary for this same-origin design. An authenticated server independently validates the session, token, resource and operation. If another origin truly needs access, configure an exact approved origin and credentials only where required, never a wildcard for credentialed response access. Practice: predict 401, 404, 409 and 200 for four fictional records; explain why a successful UI test alone cannot establish server permission.