CCyberwiki

Authorization

Each time a request arrives, the application decides whether this user or program may perform this action on this resource. That decision is authorization, in the NIST wording "the process of verifying that a requested action or service is approved for a specific entity".1 It comes after Authentication, which establishes who is asking, and takes that identity as one of its inputs. Security writing shortens the pair to AuthZ and AuthN; the bare "Auth" is discouraged because it could mean either.2

The two decisions are independent. A signed-in user of a web app is usually authorized for only part of what the app can do, and a visitor who has not signed in can still be authorized to read public resources, such as a login page or an image.1 Failures of this decision head the OWASP Top 10:2025 as Broken Access Control (A01), and every application in the data behind that edition had some form of the weakness.3

Horizontal and vertical access

Authorization rules separate users along two axes. Vertical rules separate levels of privilege: an administrator may delete accounts and an ordinary user may not. Horizontal rules keep users at the same level out of one another's data: two customers hold the same permissions, but each may read only their own orders.1 Horizontal privilege escalation, reaching another user's records at your own level, is an especially common weakness.1 Its most frequent form is the insecure direct object reference, where a record is returned because its ID was in the request. A user who reaches rights above their level, such as admin functions, has gained elevation of privilege.3

Access control models

An access control model is the way an application states its rules, and three are in common use. Role checks handle per-record and multi-tenant decisions poorly, and the number of roles tends to keep growing ("role explosion"), so the attribute and relationship models suit application development better.1

Table 1. Access control models described in the OWASP Authorization Cheat Sheet
ModelHow a decision is madeExample rule
Role-based (RBAC)Permissions belong to roles; a user holds the permissions of every role assigned to them.Users with the role admin may delete accounts.
Attribute-based (ABAC)Policies compare attributes of the user, the object and the environment, written as name-value pairs (NIST SP 800-162).Sales staff may read the customer database from the office network during working hours.
Relationship-based (ReBAC)Access follows the relationship between the user and the resource.Only the author of a post may edit it.

Where the check runs

A check holds only where the requester can change neither the check nor the data it reads: in trusted server-side code or a serverless API.3 Code in the browser fails this test. A user can edit the page, the JavaScript and every request it sends, so hiding a button or a menu item changes what the user sees and leaves the action open. Client-side checks are fit for display and nothing more.1

Next.js separates two kinds of check. An optimistic check reads the session data stored in the cookie and is used to show or hide interface elements and to redirect; a secure check reads the session from the database and guards sensitive data and actions. The secure checks belong in a Data Access Layer, one module through which every data request passes, and the framework's guide warns that the Proxy layer, which runs before every route, "should not be your only line of defense". Server Actions and Route Handlers count as public API endpoints and check the user themselves, because a page can be reached through more than one entry point.4

// app/lib/actions.ts (pattern from the Next.js authentication guide)
export async function serverAction(formData: FormData) {
  const session = await verifySession()
  const userRole = session?.role
  // Return early if user is not authorized to perform the action
  if (userRole !== 'admin') {
    return null
  }
  // ...
}

In Supabase, the check can sit in the database itself as row level security. The helper auth.uid() returns the ID of the user making the request, and a policy compares it with the owner column of each row:5

create policy "Users read their own orders"
on orders for select
to authenticated
using ( (select auth.uid()) = user_id );

Supabase keeps two kinds of user metadata. raw_user_meta_data can be changed by the signed-in user, so a role stored there can be written by the user it is meant to restrict; authorization data belongs in raw_app_meta_data, which users cannot change.5

Design principles

Deny by default: when no rule matches, the answer is a refusal, and every permission that is granted has a stated reason. Set permissions explicitly instead of relying on framework defaults, which can change between versions. Check every request, including requests for a specific record: holding access to one order does not grant access to every order. Apply least privilege along both axes, and write unit and integration tests that confirm denied requests are denied. Log failed checks and alert an administrator on repeated failures.13

Failures

CWE has two entries for the general cases. Missing Authorization (CWE-862) is code that performs no check before an action; Incorrect Authorization (CWE-863) is code whose check exists but gives the wrong answer.26 The A01 category lists the usual ways in: changing a URL or parameter, editing hidden form fields or cookies, tampering with a JSON Web Token, calling POST, PUT or DELETE routes that lack checks, and opening pages by guessing their addresses.3

A check placed in a single shared layer fails for every route behind it at once. In March 2025 Next.js published CVE-2025-29927: an attacker could skip the middleware of a self-hosted Next.js application by sending an internal header, x-middleware-subrequest, that Next.js used to mark its own sub-requests.7 The advisory states that authorization checks could be bypassed "if the authorization check occurs in middleware", rated it 9.1 (Critical) on CVSS 3.1 and classed it as CWE-285. Fixed versions were 12.3.5, 13.5.9, 14.2.25 and 15.2.3; applications that could not upgrade were told to drop requests carrying the header before they reached the server. Deployments on Vercel were not affected.8 Vercel's postmortem repeats that middleware is not recommended as the sole protection of a route.7

In SecFlash

On the Exposure page, SF-EXP-501 reports that one test account received another account's data, SF-EXP-408 reports admin links hidden only with CSS, and SF-EXP-409 reports roles, prices or owner IDs in fields the browser sends back. On the Security page, SF-SEC-725 reports a paid or private route with no login check, SF-SEC-740 reports code that saves every field a request sends, SF-SEC-723 reports a Supabase policy whose condition is always true, and SF-SEC-753 reports a policy that reads user_metadata. The same metadata problem in a live project shows on the Cloud page as SF-CLD-507.

See also

References

  1. a b c d e f g "Authorization Cheat Sheet". OWASP Cheat Sheet Series.
  2. a b "CWE-862: Missing Authorization". Common Weakness Enumeration. MITRE.
  3. a b c d e "A01:2025 Broken Access Control". OWASP Top 10:2025. OWASP Foundation.
  4. back "Authentication". Next.js Docs. Vercel.
  5. a b "Row Level Security". Supabase Docs. Supabase.
  6. back "CWE-863: Incorrect Authorization". Common Weakness Enumeration. MITRE.
  7. a b Vercel (25 March 2025). "Postmortem on Next.js Middleware bypass". Vercel Blog.
  8. back Vercel (21 March 2025). "Authorization Bypass in Next.js Middleware" (GHSA-f82v-jwr5-mffw, CVE-2025-29927). GitHub Security Advisories.