Sign inSign up free

1035. Verify a JWT Without a Library

hard 40 XP ~15 minHands-on lab

An internal tool must check the tokens issued by the auth service before acting on them. Tokens are JWTs signed with HMAC-SHA256 (HS256) and a shared secret.

Task

Create the executable script /home/student/bin/jwt-verify.sh TOKEN (secret in the environment variable JWT_SECRET). It must:

  • accept only tokens of three base64url parts whose header has "alg": "HS256" (reject none, HS512 and anything else),
  • check the signature over header.payload (compare in constant time),
  • require an exp claim in the future, and if there's an nbf claim, require it to be now or in the past,
  • on success print the payload as compact JSON with sorted keys and exit 0,
  • otherwise print a reason to stderr and exit 1; exit 2 when JWT_SECRET is unset or empty.

Python 3 is installed (no JWT library).

About this machine

Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.

Part of Networking and TLS in Practice. Next step: Encrypt Backups Properly With OpenSSL

Teaching or writing about this? Embed this lab on your page

TerminalNot started

Your machine is ready to start

A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.

No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.