Independent analysis by NHI Mgmt GroupSource article: WorkOS, “How to verify JWTs in a Next.js App Router app” (April 21, 2026)

TL;DR: JWT verification in a Next.js App Router app is easy to get almost right and still ship silent auth failures if you skip issuer, audience, algorithm, or runtime checks, according to WorkOS. The real control gap is not cryptography alone but where verification happens, because middleware, server components, and route handlers each fail differently if trust is misplaced.


At a glance

What this is: NHI Mgmt Group's analysis, drawing on WorkOS's blog post: JWT verification in Next.js App Router must be done server-side, with explicit issuer, audience, and algorithm checks, because the wrong runtime or trust boundary can create silent auth failures.

Why it matters: IAM and application security teams need this because token validation mistakes can let the wrong user through without obvious alerts, undermining both human session security and any NHI-style token-based access pattern.


Context

JWT verification is the control point where a presented token becomes an accepted identity claim. In Next.js App Router, that control point is easy to place in the wrong runtime or at the wrong layer, which turns a cryptographic check into a brittle access decision.

The identity governance problem is not limited to human sign-in flows. Any token-based access pattern, including service-to-service or delegated access, inherits the same need to verify issuer, audience, signing algorithm, and runtime compatibility before the application trusts the claims.

Next.js complicates that decision because middleware, server components, route handlers, and server actions each execute in different contexts. A verification pattern that works in one layer can fail or be bypassed in another, so placement is part of the control, not an implementation detail.


Key questions

Q: What breaks when JWT verification is done only in middleware?

A: Middleware can be bypassed by configuration mistakes and it often only decides whether a request should continue. If later code trusts injected headers instead of re-verifying claims, the application can authorize access on a value that was never checked at the point of use.

Q: Why do issuer and audience checks matter for JWTs?

A: Because a token can be cryptographically valid and still belong to the wrong issuer or the wrong application. Without issuer and audience checks, an app may accept a token minted for a different tenant or service, which turns a valid credential into an over-broad one. Those checks bind the token to the intended trust context.

Q: What are the signs that JWT validation is failing in practice?

A: Look for decoded tokens being accepted without verification, inconsistent algorithm handling across services, and tokens being honoured by APIs that should never see them. If runtime logs show one token accessing multiple unrelated services, validation is not the same as governance.

Q: Should teams verify JWTs again after middleware?

A: Yes, whenever the next layer uses the claims for authorisation, account selection, or record access. Middleware is useful for early rejection and redirects, but it should not be the sole point of trust if deeper code depends on the payload. Re-verification at the data boundary closes the gap between routing and authorisation.


Technical breakdown

What JWT verification actually proves

A JWT is only useful if the verifier checks more than the signature. Signature validation proves the token was signed by the expected key, but security also depends on validating time-based claims such as exp and nbf, plus contextual claims such as iss and aud. Those checks prevent valid tokens from being replayed in the wrong application or accepted long after their intended lifetime. In practice, verification is a combination of cryptographic integrity and policy enforcement. If either half is missing, the token may still decode cleanly while representing the wrong trust decision.

Practical implication: treat signature verification, issuer validation, audience validation, and expiry checks as one control, not optional add-ons.

Why runtime choice changes the verification library

Next.js App Router can run code on the Edge runtime or in Node.js, and that matters because not every JWT library supports both. Middleware often runs on Edge, so a Node-only library may fail before it even reaches verification logic. A library built on Web Crypto can work across Edge, Node, and browser contexts, which reduces the chance of runtime-specific auth drift. The architectural issue is not library preference alone, but whether the same verification function can execute wherever the token is checked. Consistency matters because auth logic that diverges by runtime creates uneven trust boundaries.

Practical implication: standardise on a verification library that works in every runtime where your app actually validates tokens.

Where to verify in the App Router flow

Middleware is useful for coarse gating, such as redirecting unauthenticated users, but it should not be the only place a token is checked. Server components and route handlers often need the actual claims, so they must verify again before using the payload for authorisation or data access. That split matters because middleware can be misconfigured or bypassed by alternate code paths, while server-side handlers are closer to the data they protect. The right model is layered verification: early checks for routing, and authoritative checks where claims affect business logic or access to records.

Practical implication: verify once for routing convenience and again at the data access boundary before any claim-based decision.


Threat narrative

Attacker objective: The attacker objective is to get unauthorized requests accepted as authenticated sessions or API calls by exploiting incomplete token verification.

  1. Entry occurs when an application accepts a JWT that appears structurally valid but has not been fully checked for issuer, audience, algorithm, or expiry.
  2. Credential misuse follows when verification is misplaced in a layer that the request can bypass or in a runtime that cannot reliably execute the chosen library.
  3. Impact appears as silent authentication failure, where the wrong user gains access and the application logs do not clearly flag the trust error.

Read and download The State of NHI & AI Agent Breach Report 2026, covering 150+ breaches impacting Non-Human Identities including AI Agents.


NHI Mgmt Group analysis

JWT verification is now an access-governance decision, not just a cryptographic one. The article shows that a token can be signed correctly and still be unsafe if the application accepts the wrong issuer, audience, or runtime. That means identity assurance depends on where the check runs and what assumptions the surrounding code makes. Practitioners should treat verification placement as part of the trust model, not a coding preference.

Verification layer drift is the hidden control gap in App Router deployments. Middleware, server components, and route handlers each apply different trust rules if teams are not disciplined about re-verification. A token checked only at the edge can still be relied on too broadly deeper in the request path. The practical consequence is that security teams need a consistent validation pattern across all server-side execution points.

Silent failure is the most dangerous JWT pattern because it creates false confidence. When verification skips issuer or audience checks, the application does not break loudly. It simply accepts the wrong claims and continues. That makes this issue less about authentication mechanics and more about trust boundary design, especially in applications that mix browser sessions, APIs, and delegated access.

Next.js illustrates the broader identity lesson for both human sessions and non-human tokens. Any system that accepts bearer-style credentials must define where trust begins, where it is rechecked, and which execution environment can actually enforce the policy. The decision is architectural, not just operational. Practitioners should design for repeated server-side proof, not a one-time check at the perimeter.

Claim validation has become a governance control for distributed application identity. The app must know not only whether a token is signed, but whether it was issued for this application, in this trust boundary, for this runtime. That is a stronger standard than basic authentication and aligns with modern identity governance expectations. Teams should build verification paths that fail closed everywhere a claim can affect access.

What this signals

JWT trust should be anchored at the point of use, not assumed from a prior redirect. In App Router architectures, the practical question is not whether a token passed once, but whether the current layer can independently prove it before making an access decision. That pattern applies cleanly to human sessions and to bearer-style non-human access alike.

Runtime consistency is part of the security model. If a verification function cannot run in every place the application checks identity, developers will accidentally create different trust rules for different request paths. That kind of split is a governance problem as much as a code problem, because it produces uneven enforcement across the same application.

Verified claims should be treated as temporary evidence, not permanent truth. Short token lifetimes, explicit issuer and audience binding, and server-side rechecks are what keep bearer credentials aligned with the intended session or workload. Without that discipline, the application starts accepting identity context that is no longer current.


For practitioners

  • Verify tokens at every trust boundary Check JWTs in middleware for coarse routing, then re-verify in server components, route handlers, or server actions before any claim-driven access decision.
  • Pin issuer, audience, and algorithm explicitly Configure verification so the application rejects tokens with unexpected iss, aud, or alg values instead of relying on defaults or implicit library behaviour.
  • Use runtime-compatible JWT libraries Choose a library that works in Edge and Node contexts if your App Router code runs in both, and keep auth helpers server-only.
  • Keep bearer tokens out of client-readable storage Store session tokens in httpOnly cookies and avoid localStorage or client-side verification paths that expose credentials to XSS or bypass server controls.
  • Handle expiry and clock skew deliberately Treat clock tolerance and short token lifetimes as part of the verification design so fresh tokens do not fail unpredictably and stale tokens do not persist.

Key takeaways

  • JWT verification fails when teams treat signature checking as the whole control instead of one part of a broader trust decision.
  • Next.js App Router makes verification placement matter because Edge middleware, server components, and route handlers do not share the same runtime assumptions.
  • The safest pattern is repeated server-side verification with explicit issuer, audience, and algorithm checks before any claim drives access or data use.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP API Security Top 10 addresses the attack and risk surface, while OWASP ASVS, NIST SP 800-63, NIST SP 800-53 Rev 5 and NIST CSF 2.0 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP API Security Top 10API2 — Broken AuthenticationJWT verification errors create broken authentication at the API and session boundary.
Recommendation — Enforce API2 by rejecting tokens that fail issuer, audience, or signature validation.
OWASP ASVSV10 — OAuth and OIDCThe article's token validation and JWKS patterns align with federated token verification requirements.
Recommendation — Apply V10 checks to validate JWT issuer, audience, and signing context before trusting claims.
NIST SP 800-63SP 800-63C — FederationThe article concerns trust in externally issued tokens and their federation context.
Recommendation — Use federation controls to bind tokens to the intended relying party and trust framework.
NIST SP 800-53 Rev 5IA-5 — Authenticator ManagementJWT handling depends on correct authenticator validation, rotation, and expiry handling.
Recommendation — Apply IA-5 to manage token lifetimes, verification rules, and key rotation.
NIST CSF 2.0PR.AA-05 — Access Permissions, Entitlements and AuthorizationsThe article is about ensuring only correctly verified identities receive access.
Recommendation — Use PR.AA-05 to verify that token claims match the intended access permissions before authorizing requests.

Key terms

  • Jwt Verification: JWT verification is the process of proving that a token was issued by the expected authority, has not been altered, and is still valid for the application that received it. In practice, that means checking signature, issuer, audience, and time-based claims before any access decision is made.
  • JWKS: A JWKS, or JSON Web Key Set, is a machine-readable publishing format for public keys used by clients to verify signatures or encrypt tokens. It lets consumers fetch current key material automatically instead of relying on manual distribution, which is critical when keys rotate on a schedule.
  • Edge Runtime: The Edge Runtime is a lightweight execution environment used by Next.js for middleware and other edge-deployed code. It does not provide all Node.js APIs, so identity code must use browser-compatible cryptography and avoid assumptions that only hold in a Node server.
  • Audience Claim: The audience claim is the value inside a token that identifies who or what should accept it. For non-human identity governance, it is the enforcement point that prevents a token issued for one resource from being accepted by another resource with a different trust boundary.

Deepen your knowledge

NHI governance, agentic AI identity, and machine identity lifecycle are core topics in our NHI Foundation Level course, the industry's only accredited NHI security programme. If you are building or maturing an IAM programme, it is worth exploring.
NHIMG Editorial Note
Published by the NHIMG editorial team on June 6, 2026.
Updated on October 7, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org