Menu

Myth: If a JWT Decodes, It Is Safe
📰

Myth: If a JWT Decodes, It Is Safe

DEV Community: node·Ship Stack·3 days ago
#rZwwhRQx
#devtonodejs#devto#dev#token#decode
Long article (280 words) — no AI summary yet.
Reading 0:00
15s threshold

A JWT is three base64 parts, and decoding it is trivial. That convenience creates a dangerous shortcut: if the token decodes, treat it as valid. I tested that belief with a real run, and it failed twice. Full run in this Short: https://youtu.be/1aLXVqGiOZk

What decode-only accepted

I built a decode-only check in Node and fed it 6 tokens. It accepted an expired token and a token signed with the wrong key. Decoding only reads the payload; it never asks who signed it or whether it is still valid. To a decode-only check, both of those tokens look perfectly fine.

What verify does instead

Verification is ordered. First the signature: recompute it from the header and payload with your key and compare. A token signed with the wrong key fails here and nothing else about it matters. Then the time claims: exp (not after) and nbf (not before), checked against your clock. The expired token fails here.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.