Skip to content

GUIDE 08 · WEB APPLICATIONS AND APIs

JWT security: validate tokens and access lifecycle

Decoding a JWT does not verify it. The server checks the signature using trusted keys, an allowed algorithm, expected claims and time constraints, then separately authorizes the requested action. Use a synthetic issuer and test tokens; this page does not collect production JWTs.

Scantelio editorial team · Updated

Prepare JWT scenarios

Sign-in, ownership verification and consent are required. Authorized scenarios, monitoring and CI require Pro or Business.

On this page

Decoding, verification and authorization

Decoding reads claims. Signature verification establishes integrity under the configured trust model. Authorization decides what that identity may do. A role claim visible in a decoder is not itself a permission grant, and a normally signed JWT is not encrypted merely because it has a signature.

Configure expectations on the server

Define permitted algorithms, trusted keys, issuer, audience, token purpose and time policy. Do not derive a trusted key URL solely from unverified token input. Required claims depend on your protocol; the supplied PyJWT example explicitly requires exp, iss, aud and sub for its synthetic issuer.

Reproducible local fixture; synthetic data only.
claims = jwt.decode(token, key, algorithms=["HS256"],
    audience="api-a", issuer="https://issuer.example",
    options={"require": ["exp", "iss", "aud", "sub"]})

Primary sources: Primary reference 1 · Primary reference 2

Continue: Prepare an automated API security assessment

Run negative controls

Test the correct token, wrong audience, wrong issuer, expiry, missing required expiry, an invalid signature and a missing token. Add a correct token requesting another owner’s object. The downloadable local example uses a randomly generated key, prints no token and asserts its expected outcomes.

TestExpected outcome
Valid signature and claimsAccept, then authorize the object
Wrong audienceReject
Wrong issuerReject
Expired tokenReject
Required exp missingReject
Invalid signatureReject
Missing tokenReject
Valid token, foreign objectDeny through object authorization

Handle rotation and verification failures

Define how approved keys are selected and rotated and how unknown keys or issuer outages behave. A failed or unavailable verification service must not silently grant access. Record sanitized error categories without writing raw bearer tokens into analytics, logs or support screenshots.

Primary sources: Primary reference 1 · Primary reference 2

Continue: IDOR and BOLA: test access to another user’s data

Prepare JWT scenarios

Review logout, revocation and role changes

A signed token can remain cryptographically valid after a user signs out or loses a role. The intended session and revocation policy must account for lifetime, refresh behavior and server-side state. Test the application’s actual policy; the small local example does not simulate every session lifecycle.

Keep token handling appropriate to the client

Choose storage and transport according to your threat model and platform. Avoid tokens in public URLs, analytics and shared examples. Cookie-based sessions need appropriate cookie attributes and CSRF defenses; bearer tokens still require careful handling and server-side permission checks.

Primary sources: Primary reference 1 · Primary reference 2

Continue: Exposed .env, .git or API keys: contain the leak and verify the fix

A valid JWT does not prevent IDOR

Even a correctly verified user token must be checked against the requested object, organization and role. Reuse the two-account access matrix and positive controls from the IDOR guide. Do not mark object access safe simply because signature validation succeeds.

Repeat after changes

Keep expected claims, test identities, token lifetime rules and fixture objects documented. Scantelio’s supported JWT observations depend on the supplied configuration; do not assume every issuer or audience condition was checked without the necessary inputs. Retest both rejected tokens and a legitimate user flow after fixes.

Continue: Add security checks to CI/CD and GitHub Actions

Reproducible examples and downloads

Tested with: guides-1 · Python 3.13.0 · PyJWT 2.15.1

All example data is synthetic. Downloads contain no active keys or customer records. Run examples only in your own isolated test environment.

Example verification record: versions, actions and observations

Actual Scantelio evidence panel displaying the controlled fixture result; this is not a customer scan or a full end-to-end scan
Actual Scantelio evidence panel displaying the controlled fixture result; this is not a customer scan or a full end-to-end scan. Test fixture, synthetic data.

Questions and answers

Does decoding validate the token?

No. Verification and authorization are separate steps.

Are JWT claims confidential?

A normally signed JWT is not encrypted by its signature. Do not assume its payload is secret.

Should every application require the same claims?

No. Define a policy appropriate to your protocol, then enforce it explicitly.

Does logout invalidate every issued JWT?

That depends on the application’s lifetime and revocation design; test the actual policy.

Does a valid token prevent cross-user access?

No. Object and tenant permissions still need server-side enforcement.

Can a scanner check claims without expectations?

Some observations are possible, but missing expected claims limit the conclusion.

Editorial team and sources

Scantelio editorial team: methodology and limitations. Example verified: 2026-11-02.

Apply the check to your own project

Prepare JWT scenarios

Choose your project after signing in. No scan runs without verification and consent.