KnpLabs / KnpLabs/php-github-api
Utility to validate webhook signatures
- Ngôn ngữ chính
- PHP
- Star
- 2.2k
- Fork
- 587
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
I'm not sure this should actually be implemented in this repo, as it is different from other use cases, but maintainers might still decide it fits this repository.
When implementing github webhooks, it is possible to secure them (to reject any fake requests sent to the webhook from elsewhere than Github).
Github sends a signature header in each webhook request. Their documentation shows the Ruby code to validate the request: https://developer.github.com/webhooks/securing/
I suggest providing a utility method which would validate a signature, to avoid having each developer figuring out the corresponding PHP code:
```php
class SignatureChecker
{
function validateSignature(string $signature, string $requestBody, string $secret): bool
{ // TODO implement that
}
}
```
The naming is not final of course.
I suggest that this API takes the 3 strings as arguments rather than alternatives. Here are the ones I considered but which I consider inferior:
- the secret could be a constructor argument, but this could make things harder if you manage multiple webhooks in your codebase and each of them uses a separate secret (you would have to manage separate instances)
- the signature and body could be replaced by a PSR-7 request, from which they would be extracted. But that would make things harder to use for people using frameworks not relying on PSR-7 (Symfony for instance). Having to convert the request to PSR-7 just to check the signature is adding unnecessary overhead (getting the request body and a header are easy enough to be left to the calling code)
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
The issue provides a proposed SignatureChecker::validateSignature(string $signature, string $requestBody, string $secret) entry point but names no target file or test. First review whether webhook signature validation belongs in this repository and how its existing utilities are organized. Done means the maintainers agree on the API and the utility is implemented with coverage for the documented signature-validation behavior.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- github, php
- Lĩnh vực
- api, security
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100