You receive webhook requests with a signature header. To securely verify the webhook, which steps should you perform in order? Select the correct sequence.
hard📝 Application Q15 of 15
Rest API - Webhooks and Events
You receive webhook requests with a signature header. To securely verify the webhook, which steps should you perform in order? Select the correct sequence.
A1. Retrieve secret key
2. Compare signatures
3. Compute HMAC of payload
4. Accept webhook if signatures do not match
B1. Accept webhook
2. Compute HMAC of payload
3. Compare signatures
4. Log the webhook
C1. Compute HMAC of payload
2. Retrieve secret key
3. Compare signatures
4. Reject webhook if signatures match
D1. Retrieve the secret key
2. Compute HMAC of the payload using the secret
3. Compare computed signature with header signature
4. Accept webhook if signatures match
Step-by-Step Solution
Solution:
Step 1: Retrieve the secret key
You need the secret key first to compute the HMAC signature.
Step 2: Compute HMAC of the payload using the secret
Use the secret key and payload to compute the signature.
Step 3: Compare computed signature with header signature
Check if the computed signature matches the one sent in the webhook header.
Step 4: Accept webhook if signatures match
Only accept the webhook if the signatures are the same to ensure trust.
Final Answer:
1. Retrieve the secret key
2. Compute HMAC of the payload using the secret
3. Compare computed signature with header signature
4. Accept webhook if signatures match -> Option D
Quick Check:
Secret -> Compute -> Compare -> Accept [OK]
Quick Trick:Always compute signature before comparing and accepting [OK]
Common Mistakes:
MISTAKES
Accepting webhook before verification
Comparing before computing signature
Rejecting on matching signatures
Master "Webhooks and Events" in Rest API
9 interactive learning modes - each teaches the same concept differently