The neighbourhood head’s seal on a Pos Ronda pass: real HMAC-SHA256. Change the payload, swap the secret, try alg:none and see what verify answers; then RS256…
Why it matters
Mis-verifying a JWT is a real authorization hole: a plain resident claims to be a chief, or the alg:none attack is accepted, or the secret leaks. Knowing security comes from verifying the signature on the server, with the secret, and from fixing the algorithm, prevents the costliest auth bugs in production.
The key idea
Reading is free, signing needs the key
Common mistakes
Trusting header.alg from the client (the alg:none attack) Do not let the token choose the algorithm. Fix it on the server: verify(token, secret, { algorithms: ["HS256"] }) and refuse none.
Only *decoding* the payload, forgetting to *verify* Decode (base64) working does not mean genuine. Always recompute and compare the signature with the secret on the server before trusting the contents.
A weak secret, or one committed to the repo A signature is only as safe as its secret. Use a long, random secret, keep it in env, not in the code. Leaked = anyone can issue a chief pass.
Try it in this playground
Verify a genuine pass The recomputed signature matches the stored one → verify true.
Raise role to ketua The payload changes, the old signature does not match → verify false.
Verify with the wrong secret Even a genuine pass is refused: a signature is only as safe as its secret.
Refuse alg: none With no signature, anyone can forge a payload. A correct server refuses.