wasAsked.

JWT Tampering: What's stopping me as a malicious user from opening the browser, modifying the token to grant myself admin permissions, and sending that?

Dodge Construction Network · Senior Developer · technical

Published

Asked in 2026 · Authentication & Security

Community answers

Posted by wasAsked editorial collection

The signature. A JWT is signed by the server that issued it, and any change to the header or payload makes the signature invalid. How it works - A JWT is header.payload.signature. The signature is computed over the first two parts: - HS256: HMAC-SHA256 using a secret key that only the server knows. - RS256 or ES256: signed with the issuer's private key; APIs verify with the public key. - If you decode the token in the browser and change "role": "User" to "role": "Admin", the payload changes but you cannot produce a matching signature without the secret or private key. - The API recomputes or verifies the signature on every request. The mismatch makes validation fail, and the API returns 401 Unauthorized before any endpoint code runs. So the payload is readable (it is only Base64URL-encoded, not encrypted) but not modifiable. What the server must do correctly for this protection to hold - Always validate the signature (AddJwtBearer does this by default; never disable ValidateIssuerSigningKey). - Accept only expected algorithms. Historical attacks used "alg": "none" or tricked servers into verifying an RS256 token with HS256 using the public key as the secret. Modern libraries prevent this, but pin the allowed algorithms. - Keep signing keys secret and strong (long random secrets for HMAC; private keys in Key Vault or an HSM), and rotate them. - Validate issuer, audience and expiry too, so a token issued for another API or an old token cannot be reused. Defence in depth - Do not rely on the token alone for very sensitive permissions: check roles or permissions against the database for critical admin actions, or keep tokens short-lived so role changes take effect quickly. - Never trust role information sent in other ways (request body, custom headers). - Use resource-level authorization so even a valid token only accesses permitted data. The real risk is not tampering but theft: a stolen valid token can be replayed. That is why HTTPS, short lifetimes, secure storage and refresh-token rotation matter.

Ravindra Wadile · · 0 likes

Sign in to add your answer

Related interview topics