The Key Nobody Had to Steal: Forging a JWT Through kid Path Traversal

Web & API Security Level 3/4 ~5 min November 27, 2026

The challenge

Tidewell's API picks its key file from kid. Point kid at a file whose contents you know. Forge a token with role set to admin.

What you'll learn

  • Explain what the kid header is meant for and why it is attacker-controlled
  • Spot a key lookup that builds a file path from kid
  • Use path traversal to make the server load a file with known contents
  • Explain why an empty HMAC key still produces valid signatures
  • Look up JWT keys safely by kid

Skills tested

JWT analysisPath traversalAuthentication bypass

Prerequisites

  • What a JWT is (header, payload, signature)
  • Relative paths and ../

How it works

A JWT's header can carry a kid (key ID) so the server knows which of its keys verified the signature. The header is part of the token, so kid is chosen by whoever sends the token, and it is read before the signature is checked.

Tidewell turns kid straight into a file path: fs.readFileSync(path.join('/app/keys', kid)). With ../ the client can point that at any file on the server. HS256 is symmetric: whoever knows the key bytes can sign. /dev/null reads as zero bytes on every Linux box, so the key becomes empty, and an empty key is known to everyone.

HMAC pads any key shorter than its block size with zero bytes, so an empty key and a single null byte give the same signature, which is why Burp users sign with AA==. jsonwebtoken refuses an empty string as a secret, but readFileSync without an encoding returns a Buffer, and an empty Buffer passes. This is the technique taught in PortSwigger's JWT authentication bypass via kid header path traversal lab.

Common mistakes

  • Setting kid to /dev/null. path.join('/app/keys', '/dev/null') is /app/keys/dev/null: join does not restart at an absolute path (unlike path.resolve or Python's os.path.join). Climb out with ../.
  • One ../ too few. ../dev/null lands in /app/dev/null, which does not exist. Two levels reach /; extra ../ are harmless.
  • Switching alg to none. The API pins algorithms: ['HS256'], so an unsigned token is rejected before any key is read.
  • Editing only one side. The kid trick only gives you a key you know; the privilege comes from changing role to admin in the same token.
  • Trusting the old signature. It was made with the real key over the original header and payload. The live API needs header.payload re-signed with the empty key (shown below); this workbench cannot sign, so it grades the forged header and payload.

How to defend against it

  • Never treat kid as a path, URL or SQL value: look it up in an allowlist (a map of known key IDs to keys loaded at startup, or a JWKS from your own issuer).
  • Reject empty or short HMAC keys outright; a key file that reads as zero bytes is an error, not a key.
  • Pin the expected algorithm and issuer, and prefer asymmetric keys (RS256, EdDSA) so the verifying service never holds a signing secret.
  • If files must be read, resolve the path and check it is still inside the key folder before opening it.

Full solution

Pro and Max members unlock the complete step-by-step walkthrough.

Go Pro

Community stats

92 completions
61% success rate
M2F14M3 First blood

Related Daily Hacks

42,000+ Hackers Real labs Free
Start Hacking Free or solve today's hack, no account needed