Trust but Verify the Webhook
Your extension exposes an endpoint that an e-commerce platform calls with order events. Anyone who can reach that endpoint can POST a body — the only thing separating a genuine event from a forged or tampered one is the signature header. You and the platform share a secret; for every request the platform computes an HMAC-SHA256 digest of the raw payload text, keyed with that secret, and sends it hex-encoded in a header. Your job is the verifier that decides, before any processing, whether a body can be trusted.
Requirements
Create a codeunit named "Webhook Signature Verifier" with one public procedure:
procedure VerifySignature(Payload: Text; Secret: Text; SignatureHeader: Text): BooleanRules:
- A signature entry has the form
sha256=<hex digest>, where<hex digest>is the 64-character hexadecimal encoding of the HMAC-SHA256 ofPayloadkeyed withSecret.VerifySignaturereturnstrueexactly when the header proves the payload is untouched. - To support secret rotation,
SignatureHeadermay carry several entries separated by commas, e.g.sha256=aaa..., sha256=bbb...; spaces around an entry are ignored. Returntrueif at least onesha256=entry carries the correct digest.
Solve it with Pro
You’re reading the opening of the statement. Pro unlocks the whole problem:
- The full statement
- Starter code in the browser editor
- 14 grading tests, run on Business Central 28.5
- 3 hints
- The reference solution
Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.
Already on Pro? Sign in