Sign inSign up free

1024. Verify Webhook Signatures

medium 20 XP ~11 minHands-on lab

A payment provider sends webhooks with a header like X-Signature: sha256=3f7a…: the HMAC-SHA256 of the raw request body, keyed with a shared secret, in hex. The receiver currently trusts every request.

Task

Create the executable script /home/student/bin/verify-webhook.sh BODY_FILE SIGNATURE where SIGNATURE is the header value (sha256=<hex>) and the secret comes from the environment variable WEBHOOK_SECRET. It exits:

  • 0 if the signature is valid for the body file's exact bytes (trailing newlines and \r included),
  • 1 if it's invalid, uses another algorithm prefix, or is malformed,
  • 2 if WEBHOOK_SECRET is unset or empty.

Hex digits may be upper- or lowercase. Compare in constant time, and don't put the secret on a command line. Python 3 is installed.

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: Verify a JWT Without a Library

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.