Log inBook a Demo
SecureMidSecurityAuto-graded

Fix a login that accepts forged JWTs

A security review found the login service accepts forged tokens; make it accept only genuine, unexpired ones.A login service checks each user's HS256 JWT with verify_jwt. A security review found it accepts forged tokens: anyone can mint one for any user with any role and get in. Make it return the claims only for a genuine, unexpired token, and None for anything else, without raising. Standard library only.
35 min
Python

Goals

  • A genuine, correctly signed token is accepted and its claims are returned.
  • A token with a tampered payload is rejected.
  • A token signed with the wrong secret is rejected.
  • A token that declares alg: none is rejected.
  • An expired token is rejected, including one that expires at exactly the current time.
  • Malformed tokens are rejected without raising an error.
  • The signature is compared in constant time.

What it measures

Token trustLetting genuine tokens through and turning away every forged or altered one.
Signature checksVerifying the HMAC and the declared algorithm correctly, with a constant-time comparison.
Edge casesHandling expiry at the exact boundary and malformed input without crashing.

Your environment

Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish

Start this lab

35 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo