Secure development

Implementing trustworthy JWT issuance and verification

Access lifetime: key, clock, server arranged to illustrate implementing trustworthy jwt issuance and verification.

Implementing trustworthy JWT issuance and verification connects a security requirement to the behaviour of a real feature. The relevant controls need to remain effective across custom code, integrations and the production configuration. Understanding trustworthy JWT issuance and verification helps establish which security property the feature needs and where that property is actually enforced.

What does this involve?

Session and token controls preserve an authentication decision over time. They need a defined scope, lifetime and invalidation policy. A token should be accepted because a trusted service has verified the relevant properties, not simply because its structure looks familiar.

In its most common form (signed JWT), this information is protected by the generating application (issuer) using a signature to ensure it has not been tampered with. This signature prevents attackers, such as a malicious client or user, from forging a token or modifying the claims in an existing token, for example changing the user role from a simple user to an admin or altering the client's login. The JWT can be seen as a protected identity card or certificate about a user, an application, etc. An application (presenter) presents the token to a consuming application (audience) which can verify the token's authenticity and validity and take decisions or actions based on these claims.

The last part (signature) guarantees the authenticity of both the header and the claims, either using a public/private key pair (digital signature) or a shared secret (MAC), depending on the alg header value. For our example, it is computed as:

Why it matters

Consider a realistic failure: a JWT verifier selects trust settings from the received token instead of the application's trusted policy.

A reusable credential can let someone continue acting as an account after the intended access should have ended. Long-lived access, excessive token contents and inconsistent revocation can increase the exposure beyond the initial event.

Implementation guidance should be applied to a real feature and its deployment. Framework defaults, custom handlers and integrated services all influence whether the intended protection remains effective.

How penetration testers check for it

Trace the relevant feature from its entry point to the data or operation it protects, including custom code and alternate paths.

  • Review token creation, transport, storage and acceptance.
  • Check issuer, intended recipient, lifetime and required claims.
  • Test logout, permission changes and credential replacement.
  • Inspect replay and concurrent use according to the documented design.

How to fix it

Use the appropriate maintained mechanisms and verify the result in the actual production configuration.

  • In OpenID Connect, the ID token is a JWT used to represent the identity and attributes of the connected user.
  • In OAuth 2, the access token used to obtain access to a protected resource can be a JWT.
  • A JWT is often suggested for “stateless” user sessions. However, this usage is frowned upon.
  • A DPoP Proof JWT can be used to prove possession of a private key.
  • Rotate and revoke according to the session model.
  • Keep credentials out of unnecessary URLs, logs and persistent copies.

Some designs intentionally use short-lived credentials without immediate global revocation. Assess the complete lifetime and access model before calling that design a failure.

Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.

Read about our methodology or contact pentested.com to discuss secure development and code review.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo