Skip to content

securitymedium

Verify the Webhook Signature

150 points · 0 solved

Webhooks (Stripe, GitHub, Ghost) prove they're genuine with an HMAC-SHA256 signature. The first line is T; each next line is key message signature separated by single spaces (key and message have no spaces; the signature is hex in any case). Print VALID if the signature equals HMAC-SHA256(key, message) as hex, otherwise INVALID.

In real code, compare with a constant-time function (hmac.compare_digest, crypto.timingSafeEqual, hash_equals, MessageDigest.isEqual).

2
s3cret order:42 461c316ab1abfe94b6a02bdad4c4978ffa4f4bd4520061f72a1f7478702691ad
s3cret order:43 461c316ab1abfe94b6a02bdad4c4978ffa4f4bd4520061f72a1f7478702691ad
VALID
INVALID
Learn the technique/learn/secure-coding-in-practice

main.py