{"success":true,"name":"decoding-a-jwt-is-not-verifying-it-anyone-can-forge-an-unche","description":"Reading claims from a JWT without cryptographically verifying its signature","category":"ai-brimind","path":"ai-brimind/decoding-a-jwt-is-not-verifying-it-anyone-can-forge-an-unche/SKILL.md","file":"SKILL.md","content":"---\nname: decoding-a-jwt-is-not-verifying-it-anyone-can-forge-an-unche\ndescription: \"Reading claims from a JWT without cryptographically verifying its signature\"\n---\n\n# Decoding a JWT Is Not Verifying It: Anyone Can Forge an Unchecked Token\n\n## When to use\nServer code decodes tokens to read user ID or role and trusts the result, or verification options (secret, algorithm, expiry) were never deliberately set.\n\n## Example request\ndecode-only call used server-side to get userId → tokens are just encoded text, anyone can craft one claiming to be anyone; open forgery. verification skipped 'because the token came from our own frontend' → the client is not a trust boundary, per the trust rules; misplaced faith. expiry claim read but never enforced → dead tokens live forever; unchecked clock. algorithm accepted from the token's own header → the token chooses how it's checked; fox auditing the henhouse. — each read the letter without checking the seal.\n\n## Instructions\nAct as a border guard who knows a passport's data page can be printed by anyone — only the security features prove it's real. A JWT is three encoded parts, and the payload is merely readable text: decoding it requires no secret, so its claims (user ID, role, anything) are exactly as trustworthy as a name tag a stranger wrote for themselves — the ONLY thing making a token evidence is the signature verifying it was issued with your secret and unmodified since. Server-side law: every token is VERIFIED, never merely decoded — use the library's verify function (not its decode function; the two exist side by side and the wrong one compiles fine), which checks the signature AND the expiry in one call; pin the accepted algorithm explicitly in the verify options rather than honoring whatever the token's header claims, closing the classic algorithm-confusion attacks; and treat every verification failure — bad signature, expired, malformed — as the same clean unauthorized response, per the auth rules, revealing nothing about which check failed. Decode-only has exactly one legitimate home: the client reading its OWN token for display purposes (showing the logged-in name), where nothing security-relevant hangs on it — authorization decisions live server-side regardless, per the backend-enforcement rules. Keep the secret out of code per the secrets rules, and strong enough that guessing it is fantasy. Only proceed once you can point at the verify call — with pinned algorithm and enforced expiry — standing between every token and every decision made from it.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #828\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}