Safeguard
Security Guides•

How do you test API token expiry and revocation?

A step by step test plan to confirm an API rejects expired, tampered and revoked tokens, including after logout, password change and role removal.

Safeguard Security Team
3 min read

Test token handling by replaying tokens the API should refuse: an expired one, one with an altered signature, one used after logout, and one used after a password or role change. Each replay should return 401 or 403. Any 200 response means the API is not validating or revoking tokens properly.

Why this matters

OWASP API2:2023 says an API is vulnerable if it fails to validate token authenticity or expiration, or accepts unsigned or weakly signed JWTs. It also lists letting users change sensitive settings without confirming a password. Stolen tokens are only as useful as the API lets them be.

Definitions

An access token is a credential presented on each call. Expiry limits how long it works. Revocation ends it early, for example on logout. A stateless token is validated locally, so revocation needs extra design, such as short lifetimes or a deny list.

The test plan

TestHowExpected
Expired tokenWait out a short lifetime or craft one in a test environment401
Altered payloadChange a claim, keep the old signature401
Unsigned tokenRemove the signature or set no algorithm401
Wrong audience or issuerUse a valid token from another service401 or 403
After logoutSave a token, log out, replay it401 if revocation is promised
After password changeReplay an older token401 under your policy
After role removalReplay a token that carried the old roleAccess removed, within your stated delay
Refresh token reuseUse a refresh token twiceSecond use refused if rotation is on
Token in URLSend it as a query parameterRefused, since OWASP flags tokens in URLs

Deeper JWT checks are in JWT validation checklist for API resource servers.

Decide your revocation promise first

Many systems cannot revoke an access token instantly, and that is a design choice. State the maximum delay, for example the token lifetime, and test that this delay holds. A promise you have not written down cannot be tested.

Sensitive actions

Add a test where a bearer token alone tries to change an email address or password. OWASP's scenario shows why: an attacker with a stolen token changes the email, then uses password reset to take over the account. The API should require re-authentication.

Try it yourself

Click through it at your own pace, or open it full screen. Look at how authenticated testing depends on a valid session.

Quick check

Should logout invalidate a JWT?

Only if your design supports it. Short lifetimes with refresh rotation are common. Whatever you choose, document it and test it.

Can I run these tests against production?

Prefer staging with test accounts. Replaying tokens is low risk, but password change tests alter account state.

Safeguard policies and gates can block merges that fail your checks, and the free scan at gold.safeguard.sh/scan covers dependency risk in auth libraries.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.