When adding a new feature that requires a webhook, you usually think about delivering it, signing it, maybe deduplicating it, and retry logic. But today I want to share one of the best practices for rotating webhook secrets.
The main logic of Stripe's secret rerolling
You can choose your secret expiration either immediately or up to 24 hours later.
If you choose the second option, your OLD secret will stay valid for that period, and all webhook messages will be signed with both secrets.
Maybe you will have lots of questions: is it safe? How can we sign the same message with two secrets? And the reasonable one: what is the purpose of it? Now I will answer all of them.
What if the webhook secret is compromised? Will a hacker have access for 24 hours?
Of course not. It is easy to confuse a webhook secret with an API key. So I will remind you of the difference:
A webhook secret is used by the customer's service to check the author of the message.…