Skip to content

Commit

Permalink
Add extra logging to signature filter check
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Oct 23, 2024
1 parent c274907 commit c21ba57
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jboss.resteasy.reactive.server.ServerRequestFilter;
import org.jboss.resteasy.reactive.server.WithFormRead;

import io.quarkus.logging.Log;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.container.ContainerRequestContext;
Expand Down Expand Up @@ -63,13 +64,15 @@ public Response checkSignature(ContainerRequestContext requestContext) throws IO
String signature = requestContext.getHeaderString("x-hub-signature");

if (signature == null || !requestContext.hasEntity()) {
Log.warnf("Rejecting a web hook event because of the missing signature. Posted to %s", path);
return Response.status(401).entity("Invalid request. Missing x-hub-signature header.").build();
}
try (InputStream entityStream = requestContext.getEntityStream()) {
byte[] payload = entityStream.readAllBytes();

final String calculatedSignature = sign(mac, payload);
if (!calculatedSignature.equals(signature)) {
Log.warnf("Rejecting a web hook event because of the signature mismatch. Posted to %s", path);
return Response.status(401).entity("Signatures do not match.").build();
}
requestContext.setEntityStream(new ByteArrayInputStream(payload));
Expand Down

0 comments on commit c21ba57

Please sign in to comment.