Improve webhook signature validation #1984
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why?
This update clarifies a non-obvious behavior in
WebhookSignature::verifyHeader. Previously, it was not clear from the docblock that timestamp validation is skipped not only whentoleranceisnull, but also when0is passed. Since the actual check only runs when$tolerance > 0, passing0effectively disables tolerance validation.The signature header parsing logic previously relied on implicit assumptions about the header format. By explicitly validating key=value pairs, the code now safely ignores malformed values (e.g.
t,v1) that would previously throw exceptions, instead of attempting to process them.What?
WebhookSignature::verifyHeaderdocblock that timestamp validation is skipped when tolerance isnullor02 === \count($itemParts)check inWebhookSignature::getTimestampto safely ignore malformed header parts (e.g.t,v1) and prevent exceptions2 === \count($itemParts)check inWebhookSignature::getSignatures