JWT Testing Checklist for QA Engineers
To test a JSON Web Token (JWT), decode it, then check that the server rejects every version of it that it shouldn't trust: a changed payload, a removed or none signature, an expired token, and a token meant for a different audience or issuer. If any of those still returns 200, authentication is broken. This checklist shows how a QA engineer can run those checks with Burp Suite and automate them.
JWT problems fall under API2:2023 Broken Authentication in the OWASP API Security Top 10. They are usually configuration and library mistakes, which makes them very testable.
Only test applications you're authorized to test: your own product, a staging environment you have permission for, or a bug bounty programme whose scope includes the target.
1. Decode the token and read what's inside
A JWT is three base64url parts separated by dots: header.payload.signature. The header and payload are encoded, not encrypted, so anyone holding the token can read them. Decode one from your test session:
node -e "const p=process.argv[1].split('.'); console.log(JSON.parse(Buffer.from(p[0],'base64url')), JSON.parse(Buffer.from(p[1],'base64url')))" "$TOKEN"
Avoid pasting real production tokens into online decoders. Decode locally, or use the JWT Editor extension in Burp Suite. Then note:
- The
algin the header (HS256,RS256, and so on). - Identity and permission claims:
sub,role,tenantId,scope. - Time claims:
exp,nbf,iat, and who issued the token (iss) and for whom (aud). - Anything sensitive that shouldn't be there: passwords, personal data, internal IDs or secrets.
2. Tamper with the payload and keep the signature
Change one claim, for example "role": "user" to "role": "admin" or the sub to another user's ID, re-encode the payload and send the token with the original signature. The server must reject it, usually with 401. If it accepts the change, it isn't verifying the signature. Do the same for each claim the application trusts.
3. Test the "alg: none" and algorithm-confusion cases
- alg none: set the header to
{"alg":"none","typ":"JWT"}, change the payload and remove the signature (keep the trailing dot). A correct server rejects it. Also tryNoneandNONE, because some libraries compare case-sensitively. - Algorithm confusion: if the app signs with
RS256, try re-signing the token asHS256using the public key as the HMAC secret. A server that lets the token choose its own algorithm may accept it. Burp's JWT Editor can run this attack for you. - Pinned algorithm: the fix is for the server to allow only the algorithm it expects, and never trust the token's header to decide.
4. Check for weak signing secrets
With HS256, the whole scheme depends on the secret being long and random. On a staging token you're authorized to test, you can try a wordlist offline. Hashcat supports JWT with mode 16500. If a short or default secret like secret or the app's name cracks, anyone can forge tokens. Report it and recommend a random secret of at least 32 bytes, or an asymmetric algorithm.
5. Validate the claims, not just the signature
A token with a valid signature can still be wrong for the request. Test each of these and expect a rejection:
- Expired: a token whose
expis in the past. - Not yet valid: a token with a future
nbf. - Wrong audience: a token issued for a different service (
aud). - Wrong issuer: a token from another environment, such as staging used against production (
iss). - No expiry at all: a token without
expthat the server happily accepts forever.
6. Test header parameters that point to keys
Some headers tell the server where to find the verification key: kid, jku, jwk and x5u. The server must never trust a key the token supplies for itself. Try these:
- An embedded
jwkcontaining your own public key, signed with your own private key. - A
jkuorx5uURL pointing to a host you control. - A
kidwith unexpected values, such as path-like strings or quotes, to see whether it's used unsafely in a file lookup or database query.
7. Test the token's lifecycle
- Logout: does the old token still work after logout? Short-lived tokens plus a server-side revocation list or refresh-token rotation handle this.
- Password change or role change: do existing tokens keep the old permissions?
- Refresh tokens: can one be reused after rotation, or used from a different client?
- Storage: a token in
localStorageis readable by any XSS bug. A cookie should beHttpOnly,Secureand have a suitableSameSitevalue. - Lifetime: access tokens should be short-lived, typically minutes and not days.
Once authentication holds, check authorization too, with the two-account method in my IDOR testing checklist.
8. Automate the checks in Playwright
Manual findings should become regression tests. Playwright's API testing support is enough for this. Here are two examples, one for alg: none and one for a tampered payload:
import { test, expect } from "@playwright/test";
const b64 = (o) => Buffer.from(JSON.stringify(o)).toString("base64url");
test("rejects an unsigned alg=none token", async ({ request }) => {
const token = `${b64({ alg: "none", typ: "JWT" })}.${b64({ sub: "1042", role: "admin" })}.`;
const res = await request.get("/api/profile", {
headers: { Authorization: `Bearer ${token}` },
});
expect(res.status()).toBe(401);
});
test("rejects a tampered payload", async ({ request }) => {
const [h, , s] = fixtures.userA.token.split(".");
const forged = `${h}.${b64({ sub: "1", role: "admin" })}.${s}`;
const res = await request.get("/api/profile", {
headers: { Authorization: `Bearer ${forged}` },
});
expect(res.status()).toBe(401);
});
Add expired-token and wrong-audience cases the same way, using tokens generated by your test environment. Run them in CI alongside your functional suite, as described in QA automation and security testing in one CI pipeline.
9. Report JWT findings so they get fixed
- Title: state the effect, e.g. "API accepts unsigned tokens, so any user can impersonate an admin".
- Steps: the original token claims, the exact change you made, the request and the response you got back.
- Impact: which accounts or roles an attacker could reach, and whether the token works on every endpoint or only some.
- Fix: verify with a maintained library, pin the allowed algorithms, validate
exp,issandaud, and use a long random secret or an asymmetric key pair.
Key takeaways
- A JWT is readable by anyone who has it, so it must not hold secrets.
- The server must verify the signature, pin the algorithm and reject
none. - Check
exp,nbf,issandaud, not only the signature. - Never trust key locations (
jwk,jku,kid) supplied by the token. - Test logout, refresh and role changes, because the token's lifecycle is where many bugs hide.
- Turn every confirmed finding into an automated test. For more background, see PortSwigger's JWT attacks guide.
FAQ
Is a JWT encrypted?
No. A standard signed JWT (JWS) is only base64url-encoded and signed. Anyone can read its contents, but only the holder of the key can create a valid signature. If you need to hide the contents, use an encrypted token (JWE) or keep the data on the server.
What is the most common JWT vulnerability?
Weak or missing verification: accepting alg: none, not checking the signature, using a guessable HS256 secret, or skipping expiry and audience checks. All of them are quick to test, which is why they belong in a QA security checklist.
Which tools do I need to test JWTs?
Burp Suite with the JWT Editor extension for manual tampering, Hashcat for offline secret testing on tokens you're authorized to test, and Playwright or any API test tool to automate the checks in CI.