#306 Forward deployed engineer interviews 6.1 min
Webhooks Done Right: Signatures, Retries and Replays
Anyone can POST to your webhook URL. Four questions to ask of every message: forged, changed, old or repeated?
Run the attacks
Copy the code folder first. Run python run.py. Match each printed line to one of the four checks: signature, unchanged body, age and event id. You should see 401 for the forged and the changed message, 400 for the old one, and a 200 duplicate for the repeat.
A hint
The receiver checks in this order: signature, age, then event id.
Widen the time window
In webhook.py change TOLERANCE = 300 to TOLERANCE = 900. Predict what happens to the message that is 10 minutes old, then run python run.py. With this change it prints (200, 'processed') and evt_3 joins the processed list. What does a wider window let an attacker do? Then change TOLERANCE back to 300, because the next exercise needs it.
A hint
10 minutes is 600 seconds.
Find the edge of the window
In run.py change clock.now - 600 to clock.now - 301 and run it, then change it to clock.now - 299 and run again. Predict each result first. At 301 seconds the old message prints (400, 'too old'), and at 299 it prints (200, 'processed'). The printed label still says '10 minutes old', which is no longer true. When you have finished, change clock.now - 299 back to clock.now - 600.
A hint
The receiver refuses a message more than TOLERANCE seconds away from now.
Make the line worse
In run.py in the flaky function change calls["n"] <= 2 to calls["n"] <= 4. The sender makes at most 4 tries. Predict what the flaky line and the dead letters will show, then run it. With this change the flaky line prints 'delivered on try 0' (a stale label: it means the sender gave up), dead letters become ['evt_4', 'evt_5'], and evt_4 is still processed exactly once. When you have finished, change 4 back to 2.
A hint
The receiver does the work before the reply is lost, so giving up does not undo it.
These tasks are for you to try on your own machine. Nothing is checked or saved.
What this does not show
No network: the line is a function and the clock is a number. The secret is made up and the signing is simplified (the Standard Webhooks scheme also signs the message id). The seen list is in memory and never expires. A request with a missing header raises an error instead of a 401. Sources are vendor pages, not the specification.
Up next in Forward deployed engineer interviews
More in Forward deployed engineer interviews
Related videos
- #302 Forward Deployed Engineer Interview: What Is Tested Forward deployed engineer interviews
- #303 The FDE Decomposition Round: Vague Ask to a Plan Forward deployed engineer interviews
- #305 Retry a Flaky API Without Duplicates: Idempotency Keys Forward deployed engineer interviews
- #308 Two Systems Edit One Record: Lost Updates Explained Forward deployed engineer interviews
