Skip to content
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

[CAT-1728] Don't catch JSON decoding error on webhook event verification in Java #158

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ public class WebhookEventVerifier {
* @param rawEventBody the raw event body
* @param hexSignature the hex signature
* @return the webhook event
* @throws OnfidoInvalidSignatureError the onfido exception
* @throws OnfidoInvalidSignatureError on verification error
* @throws JsonParseException on JSON parsing error
*/
public WebhookEvent readPayload(String rawEventBody, String hexSignature)
throws OnfidoInvalidSignatureError {
throws OnfidoInvalidSignatureError, JsonParseException {
Mac sha256Hmac;
SecretKeySpec secretKey;

Expand All @@ -100,14 +101,10 @@ public class WebhookEventVerifier {
throw new OnfidoInvalidSignatureError("Invalid signature for webhook event");
}

try {
JsonReader jsonReader = new JsonReader(new StringReader(rawEventBody));
jsonReader.setLenient(true);
JsonReader jsonReader = new JsonReader(new StringReader(rawEventBody));
jsonReader.setLenient(true);

return gson.fromJson(jsonReader, WebhookEvent.class);
} catch (JsonParseException e) {
throw new OnfidoInvalidSignatureError("Invalid payload for webhook event", e);
}
return gson.fromJson(jsonReader, WebhookEvent.class);
}

private String encodeHexString(byte[] byteArray) {
Expand Down