CCyberwiki

Authentication

Authentication, abbreviated AuthN, is the process by which a system checks that a user, program or website is the one it claims to be.1 The check establishes that the party asking for access controls the secrets, called authenticators, that are registered to an account.2 Authorization (AuthZ) is the separate, later decision about what that identity may do.3

Factors and assurance levels

An authenticator proves one of three kinds of factor: something the person knows (a password), something they have (a phone or a security key) or something they are (a fingerprint). A biometric does not count as an authenticator on its own; it is accepted only together with a physical device.2

NIST SP 800-63B-4 grades the strength of a sign-in in three Authentication Assurance Levels. AAL1 accepts one factor. AAL2 requires two distinct factors, as in multi-factor authentication, and the service must also offer a phishing-resistant authentication method. AAL3 requires proof that the user holds a private key, through a public-key protocol, on an authenticator from which the key cannot be exported.2

Table 1. Common authenticator types in NIST SP 800-63B-4
TypeFactorPhishing-resistant
Password or PINSomething you knowNo
Look-up secret, such as saved recovery codesSomething you haveNo
One-time password from an app or deviceSomething you haveNo
Out-of-band device, such as a code by text message or a push promptSomething you haveNo
Cryptographic key held on a deviceSomething you haveCan be; required at AAL3

Authentication on the web

A web application authenticates the user once, at sign-in, and then issues a session: a cookie or a token that the browser sends with every later request. Each later request is authenticated again, by the server checking that the session it receives is valid.4 Cookies, lifetimes and logout are covered in Session management, signed tokens in JSON Web Token.

In the HTTP authentication framework, a server that needs credentials answers 401 Unauthorized with a WWW-Authenticate header naming a scheme, and the client repeats the request with an Authorization header. A request with valid credentials that lack permission gets 403 Forbidden. HTTP Basic Authentication sends the user name and password encoded in base64, which is not encryption, so it is safe only over HTTPS.5

Passwords

In SP 800-63B-4, a password that is the only factor must be at least 15 characters long; one used only as part of multi-factor sign-in may be as short as 8. Services should accept at least 64 characters, spaces and Unicode. They must not impose composition rules such as a required digit or symbol, and must not force periodic changes, only a change after evidence of compromise. Each new password is compared with a blocklist of breached, common and context-specific values, password managers and autofill must work, and failed attempts must be rate-limited.2 Rotation and complexity rules were dropped because they push users to reuse passwords and to pick weak ones.6

The server stores a salted hash of each password. Hashing works in one direction only, while an encrypted password can be turned back into the original. Fast hashes such as SHA-256 let an attacker who copies the table test guesses quickly. Suitable choices are Argon2id with at least 19 MiB of memory, 2 iterations and a parallelism of 1, or, on older systems, bcrypt with a work factor of 10 or more and a 72-byte input limit.7

Common failures

An authentication failure is any case in which a system can be made to accept an invalid user as legitimate. Typical causes are sign-in forms open to Credential stuffing, password spraying and Brute-force attack guessing, default accounts such as admin with the password admin, recovery by security questions, passwords stored in plain text or with weak hashes, missing multi-factor authentication, session identifiers placed in the URL, and sessions that survive logout.6 The OWASP Top 10:2025 groups these flaws as A07, Authentication Failures, mapped to 36 CWEs.6 The parent weakness, CWE-287, Improper Authentication, is accepting an identity claim without proving it or proving it poorly; its child CWE-306 covers functions that ask for no proof of identity at all.3

Responses can also reveal which accounts exist. A wrong password, an unknown account and a locked account should all get the same message, for example "Login failed; Invalid user ID or password.", and take the same time to process, because a measurable delay is a second signal. The failed-attempt counter belongs to the account, so that requests spread over many IP addresses still count.1

Next.js middleware bypass, 2025

Some Next.js applications checked the session cookie in middleware, the code that runs before a page renders. On 21 March 2025 Vercel published CVE-2025-29927, rated Critical with a CVSS score of 9.1: an external request carrying the internal x-middleware-subrequest header made the server skip middleware, and every check inside it.8 Next.js used the header to stop middleware from calling itself in a loop. The flaw had been reported privately on 27 February. Fixed releases were 15.2.3, 14.2.25, 13.5.9 and 12.3.5; applications hosted on Vercel, Netlify and Cloudflare Workers were never affected, because their routing runs in a separate system. In its postmortem, Vercel advised against middleware as the only protection for a route.9

Checking the session in code

The Next.js guide calls a cookie check in middleware (named Proxy from Next.js 16) "optimistic" and puts a data access layer behind it: one function that verifies the session, called from every data request, Server Action and Route Handler.4

// app/lib/dal.ts, from the Next.js authentication guide
export const verifySession = cache(async () => {
  const cookie = (await cookies()).get('session')?.value
  const session = await decrypt(cookie)
  if (!session?.userId) {
    redirect('/login')
  }
  return { isAuth: true, userId: session.userId }
})

With Supabase, server code reads the user with supabase.auth.getClaims(), which verifies the token's signature on every call. getSession() reads the session from the cookie without checking it, and a cookie can be forged, so server code must not trust it.10

const { data } = await supabase.auth.getClaims()

Prompt for a coding agent

List every page, Server Action, Route Handler and API route in this project that reads or changes user data or calls a paid service. Check that each one verifies the session on the server, close to the data, not only in middleware or the browser. With Supabase, use supabase.auth.getClaims() in server code, never getSession(). Make sign-in, sign-up and password reset return the same message whether or not the account exists. List what you changed and anything you were unsure about.

In SecFlash

On the Security page, SecFlash reports a private or paid route with no login check as SF-SEC-725, token checks that are switched off or weak as SF-SEC-738, a sign-in route with no rate limit as SF-SEC-727, and HTTP Basic or Digest sign-in over plain HTTP as SF-SEC-648. When one test account's data is returned to a request with no session, it reports SF-EXP-502 on the Exposure page. On the Cloud page, it reports a Supabase project that accepts passwords under 8 characters as SF-CLD-531, one that does not check new passwords against known leaks as SF-CLD-532, and too few second-factor options as SF-CLD-524.

See also

References

  1. a b "Authentication Cheat Sheet". OWASP Cheat Sheet Series.
  2. a b c d "NIST SP 800-63B-4, Digital Identity Guidelines: Authentication and Authenticator Management". NIST.
  3. a b "CWE-287: Improper Authentication". Common Weakness Enumeration. MITRE.
  4. a b "How to implement authentication in Next.js". Next.js Docs. Vercel.
  5. back "HTTP authentication". MDN Web Docs. Mozilla.
  6. a b c "A07:2025 Authentication Failures". OWASP Top 10:2025. OWASP Foundation.
  7. back "Password Storage Cheat Sheet". OWASP Cheat Sheet Series.
  8. back Vercel (21 March 2025). "Authorization Bypass in Next.js Middleware, GHSA-f82v-jwr5-mffw". GitHub Security Advisories.
  9. back Vercel (March 2025). "Postmortem on Next.js Middleware bypass". Vercel Blog.
  10. back "Setting up Server-Side Auth for Next.js". Supabase Docs. Supabase.