Independent analysis by NHI Mgmt GroupSource article: WorkOS, “How to handle JWT in PHP” (May 11, 2026)

TL;DR: Secure JWT handling in PHP depends on signature verification, strict claim validation, and JWKS-backed key rotation, with firebase/php-jwt providing the standard library path for HS256, RS256, and cached remote keys according to WorkOS. The governance point is simple: unverified tokens are bearer credentials, not trusted identity assertions, and access logic must never depend on payloads before verification.


At a glance

What this is: NHI Mgmt Group's analysis, drawing on WorkOS's blog post: PHP JWT validation depends on signature verification, claim checks, and JWKS-backed key rotation.

Why it matters: It matters because PHP teams often treat decoded token payloads as trustworthy before verification, which turns bearer tokens into an access-control bypass risk for API and application authentication flows.


Context

JWT validation in PHP is really a question of trust boundaries: a token can be decoded before it is verified, but decoded claims are not yet authoritative. The article centres on how PHP applications should verify signatures, check registered claims, and use key rotation safely in modern API authentication flows.

The identity governance implication is straightforward for NHI and application access alike. JWTs are bearer credentials, so verification must happen before any routing, authorisation, or user lookup logic depends on the token content. In PHP, that means algorithm-specific validation and JWKS-aware key handling, not ad hoc decoding.


Key questions

Q: How should security teams prevent unverified JWT claims from driving access decisions?

A: Treat every decoded JWT as untrusted until signature verification, algorithm binding, and claim checks succeed. The safest pattern is centralised verification in middleware or a shared helper, followed by authorisation logic that only reads claims from a verified token. That keeps payload data from becoming an input to access control before it is authenticated.

Q: When should organisations prefer JWKS over static PEM files for JWT verification?

A: Organisations should prefer JWKS whenever multiple services need to verify tokens from the same issuer, or whenever key rotation is expected. JWKS lets verifiers select the correct key by kid, cache responses, and refresh automatically. Static PEM files are manageable only in very small environments with tightly controlled distribution.

Q: What breaks when JWTs are signed without strict issuer and audience validation?

A: Without issuer and audience validation, a token may be accepted in the wrong application boundary or from the wrong trust context. That creates authorization confusion, weakens token replay defenses, and increases the chance that a valid token is treated as trustworthy where it should not be. Validation is part of proving token provenance and intended use.

Q: What should PHP teams do immediately after a JWT signing key is rotated?

A: Keep verification aligned to the published JWKS, continue accepting the retired key only until all tokens signed with it can expire, and confirm that cached key lookups refresh correctly. Then monitor for verification failures that indicate stale caches or missing kid values, because those are the first signs that rotation and verification are drifting apart.


Technical breakdown

Why signature verification must come before any claim use

A JWT is only a signed statement until the verifier checks the signature with the expected key and algorithm. In PHP, the danger is not decoding a token, but treating the decoded payload as evidence before verification succeeds. Libraries such as firebase/php-jwt enforce this by binding a key to an algorithm, which prevents algorithm confusion and other substitution attacks. Signature verification establishes provenance and integrity, but it does not by itself prove the token is still valid for the intended audience or issuer.

Practical implication: verify the signature first, then allow claims to influence authentication or authorisation logic.

How JWKS and CachedKeySet change key rotation

JWKS replaces manually distributed public keys with a published key set that verifiers can fetch by key ID, or kid. CachedKeySet adds local caching and refresh behaviour so verifiers can keep working while keys rotate, which is especially important when multiple services validate the same issuer's tokens. This model reduces operational drift because the verifier no longer depends on hand-updated PEM files or a single static key. It also narrows the window in which retired keys can still verify tokens if rotation and cache lifetimes are managed correctly.

Practical implication: use JWKS for distributed verification and set cache and retirement windows so rotated keys stop working when intended.

Which JWT claims need strict validation in PHP

A valid signature does not make every token acceptable. The standard claims that matter most are iss, aud, and exp because they define who issued the token, who it is for, and whether it is still within its accepted lifetime. In practice, these checks stop replay across services, cross-tenant token reuse, and acceptance of stale credentials. The article also highlights that Bearer tokens must be handled as transport credentials, not application data, which means claim validation belongs in the verification layer rather than in scattered endpoint logic.

Practical implication: reject tokens that fail issuer, audience, or expiration checks even when the signature is correct.


NHI Mgmt Group analysis

Bearer-token trust is the broken premise, not the decoding step. PHP developers can always inspect a JWT before verification, but inspection is not trust. The security failure begins when downstream logic consumes decoded claims as if they were authenticated identity data. That premise is incompatible with bearer credentials, because the token's contents are only authoritative after signature and claim validation succeed. Practitioners should treat pre-verification payloads as untrusted input, not identity evidence.

JWKS-backed verification turns key rotation into a governance control. Manual public-key distribution creates a stale-key problem whenever issuers rotate signing keys across services. JWKS plus cached lookups shifts the verifier from static key management to published key discovery, which is the operational model modern distributed identity systems need. The named concept here is verification-time key trust: the verifier should trust only the key that is current for the presented kid and issuer, not a locally hard-coded file.

Algorithm binding is a control boundary, not an implementation detail. Accepting whatever algorithm the header advertises hands the attacker a negotiation surface the application should never offer. Binding verification to the expected algorithm closes the confusion path that appears when HS256, RS256, or other options are treated as interchangeable. For identity teams, this is the same lesson seen across token systems: trust must be expressed explicitly at verification time, not inferred from the token itself.

JWT claim checks are access governance, not token hygiene. The article's focus on iss, aud, and exp shows that token validation is really an authorisation boundary with identity semantics attached. If those checks are weak, services can accept tokens issued for other audiences, older sessions, or the wrong trust domain. That is why claim validation belongs in central middleware or shared libraries, not in one-off controller code. The practitioner conclusion is simple: govern acceptance conditions centrally or create inconsistent trust across the application estate.

What this signals

Verification-time key trust: JWT programmes fail when verifiers treat locally stored keys as permanent truth. JWKS changes the control model so the application trusts the current published key for a given kid and issuer, which is the right pattern for distributed PHP services.

Access decisions should never depend on decoded payloads alone, because a JWT is a bearer credential whose claims only become authoritative after verification. That shifts JWT handling from token parsing to trust enforcement at the application boundary.


For practitioners

  • Verify signatures before reading claims Centralise JWT verification so no route, middleware, or helper consumes decoded payloads before signature validation succeeds. Bind verification to the expected algorithm and issuer context, then reject tokens that fail verification immediately.
  • Enforce iss, aud, and exp checks Require issuer, audience, and expiration validation on every protected endpoint, and keep the acceptable leeway narrow. Treat any token that fails one of those checks as unauthorised even if the signature is valid.
  • Move distributed verification to JWKS Use a JWKS endpoint for public-key discovery so services can resolve kid values without manual PEM redistribution. Keep old keys available only for as long as tokens signed with them must remain valid.
  • Test wrong-key and wrong-algorithm cases Add negative tests for tampered payloads, mismatched keys, unsupported algorithms, expired tokens, and tokens with incorrect issuer or audience values. Use those tests to prove your verification layer fails closed.

Key takeaways

  • JWT validation in PHP is an access-control problem first and a parsing problem second.
  • JWKS-backed key rotation reduces drift, but only if verifiers refresh keys and retire old ones on schedule.
  • Signature verification, algorithm binding, and claim checks must all succeed before a token can influence authorisation.

Standards & Framework Alignment

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

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

FrameworkControl / ReferenceRelevance
OWASP Non-Human Identity Top 10NHI-04 — Insecure AuthenticationThe article is about authenticating and verifying bearer JWTs before trust is granted.
NHI-07 — Long-Lived SecretsJWT signing keys and bearer tokens create lifecycle risk when rotation and expiry are weak.
Recommendation — Apply NHI-04 by rejecting any token that is not fully verified before use. Use NHI-07 to enforce short token lifetimes and timely key retirement.
NIST SP 800-53 Rev 5IA-5 — Authenticator ManagementJWT secrets and signing keys are authenticators whose lifecycle must be governed.
Recommendation — Use IA-5 to manage token and signing-key lifecycle, including rotation and revocation.
NIST CSF 2.0PR.AA-05 — Access Permissions, Entitlements and AuthorizationsClaim validation and issuer/audience checks govern whether a token is authorised for a service.
Recommendation — Apply PR.AA-05 to validate access conditions before a JWT can authorise a request.
OWASP API Security Top 10API2 — Broken AuthenticationInvalid JWT handling in APIs is a direct authentication failure mode.
Recommendation — Use API2 to ensure API requests fail when JWT authentication or verification is incomplete.

Key terms

  • 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.
  • Runtime Binding: Runtime binding links an AI agent’s actions to the initiating human’s current identity, role, and clearance at the moment of decision. It is stronger than a static delegation record because it rechecks whether the human is actually entitled to the access the agent is trying to use right now.
  • Bearer Credential: A bearer credential is a secret that grants access to whoever possesses it, without requiring proof of the original user at every request. In SaaS and cloud environments, OAuth tokens, session cookies, and similar artifacts behave this way, which makes theft and replay a direct access path.
  • Claim Validation: Claim validation is the process of checking whether token fields such as issuer, audience, subject, and expiry match the expected security context. It is the control that prevents a validly signed token from being accepted in the wrong place, for the wrong system, or after its intended lifetime.

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 5, 2026.
Updated on October 7, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org