KnpLabs / KnpLabs/php-github-api

Utility to validate webhook signatures

Abierto
#741 10 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

documentation enhancement good first issue
Lenguaje dominante
PHP
Estrellas
2.2k
Forks
585
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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:

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)

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

El issue propone un punto de entrada SignatureChecker::validateSignature(string $signature, string $requestBody, string $secret), pero no indica ningún archivo de destino ni prueba. Primero revisa si la validación de firmas de webhook pertenece a este repositorio y cómo están organizadas sus utilidades existentes. Se considera terminado cuando los maintainers estén de acuerdo con la API y la utilidad esté implementada con cobertura del comportamiento documentado de validación de firmas.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
github, php
Área
api, security
Tipo de issue
Nueva funcionalidad
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.