-
Notifications
You must be signed in to change notification settings - Fork 682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[10.x] Refactor handling of invalid webhook signatures #791
[10.x] Refactor handling of invalid webhook signatures #791
Conversation
We can rid of the `\Illuminate\Contracts\Foundation\Application` dependency in the `VerifyWebhookSignature` constructor, by manually throwing a 403 exception. This simplifies both the implementation and the tests, and it allows us to pass the message and the original exception to the exception handler.
799aea0
to
6ce9d8a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, wauw. Very cool. Thanks! :)
On thing on my mind is people extending the class and using the app property but that seems very unlikely tbh. |
Yeah I doubt people would want to extend this middleware. :) |
@driesvints should we remove the config repository dependency as well? We are using |
@sebdesign I think that was still needed for the tests but if you can simplify it then go for it. |
@driesvints I'll do it tonight! The goal is to simplify tests as well. |
Similarly to laravel#791, we can remove the `\Illuminate\Contracts\Config\Repository` in the `VerifyWebhookSignature`'s constructor. For consistency, the configuration is accessed with the `config()` helper like the rest of the code. Since we don't need to mock the configuration repository anymore, the test has been moved to the integration suite, because we need to bootstrap the framework. As a bonus, I have added tests for checking [replay attacks](https://stripe.com/docs/webhooks/signatures#replay-attacks) against the tolerance configuration setting.
We can rid of the
\Illuminate\Contracts\Foundation\Application
dependency in theVerifyWebhookSignature
constructor, by manually throwing a 403 exception.This simplifies both the implementation and the tests, and it allows us to pass the message and the original exception to the exception handler.