Skip to content

Add webhook verification support#21

Merged
bpapillon merged 2 commits intomainfrom
webhook-verification
Mar 27, 2025
Merged

Add webhook verification support#21
bpapillon merged 2 commits intomainfrom
webhook-verification

Conversation

@bpapillon
Copy link
Copy Markdown
Contributor

No description provided.

@bpapillon bpapillon self-assigned this Mar 27, 2025
@bpapillon bpapillon force-pushed the webhook-verification branch from 7ddb4e9 to 587d578 Compare March 27, 2025 15:13
@bpapillon bpapillon force-pushed the webhook-verification branch from 587d578 to 52d7aa7 Compare March 27, 2025 15:32
@bpapillon bpapillon requested review from a team and Copilot March 27, 2025 17:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for verifying webhook signatures via HMAC-SHA256, including implementation of the verifier and accompanying tests, a simple test server, and updated documentation.

  • Added WebhookVerifier and WebhookSignatureException for signature verification
  • Implemented unit tests in WebhookVerifierTest and an HTTP test server in WebhookTestServer
  • Updated README.md with usage instructions for verifying webhook signatures

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/test/java/com/schematic/webhook/WebhookVerifierTest.java Added tests to ensure correct signature computation and verification
src/main/java/com/schematic/webhook/server/WebhookTestServer.java Introduced a test server to simulate webhook requests and verify signatures
src/main/java/com/schematic/webhook/WebhookVerifier.java Implemented webhook signature verification logic using HMAC-SHA256
src/main/java/com/schematic/webhook/WebhookSignatureException.java Created a custom exception for signature verification failures
README.md Updated documentation with instructions for webhook signature verification
Files not reviewed (1)
  • .fernignore: Language not supported

Comment on lines +137 to +138
exchange.sendResponseHeaders(statusCode, body.length());

Copy link

Copilot AI Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using body.getBytes(StandardCharsets.UTF_8).length instead of body.length() when setting the response header to accurately calculate the number of bytes, especially for non-ASCII characters.

Suggested change
exchange.sendResponseHeaders(statusCode, body.length());
exchange.sendResponseHeaders(statusCode, body.getBytes(StandardCharsets.UTF_8).length);

Copilot uses AI. Check for mistakes.
* @return The byte array
* @throws WebhookSignatureException if the hex string is invalid
*/
private static byte[] hexToBytes(String hex) throws WebhookSignatureException {
Copy link

Copilot AI Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be beneficial to validate that the hex string has an even length before processing, as an odd-length string would indicate an invalid format.

Suggested change
private static byte[] hexToBytes(String hex) throws WebhookSignatureException {
private static byte[] hexToBytes(String hex) throws WebhookSignatureException {
if (hex.length() % 2 != 0) {
throw new WebhookSignatureException("Invalid hex string format: length must be even");
}

Copilot uses AI. Check for mistakes.
@bpapillon bpapillon merged commit c4093bc into main Mar 27, 2025
3 checks passed
@bpapillon bpapillon deleted the webhook-verification branch March 27, 2025 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants