Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion src/main/java/com/stripe/net/Webhook.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ private static long getTimestamp(String sigHeader) {
for (String item : items) {
String[] itemParts = item.split("=", 2);
if (itemParts[0].equals("t")) {
return Long.parseLong(itemParts[1]);
try {
return Long.parseLong(itemParts[1]);
} catch (NumberFormatException e) {
return -1;
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/test/java/com/stripe/net/WebhookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ public void testMalformedHeader() throws SignatureVerificationException {
assertEquals("Unable to extract timestamp and signatures from header", exception.getMessage());
}

@Test
public void testMalformedTimestampValue() throws SignatureVerificationException {
// Test with non-numeric timestamp value - should throw SignatureVerificationException,
// not NumberFormatException
final String sigHeader = "t=not_a_number,v1=somesignature";

Throwable exception =
assertThrows(
SignatureVerificationException.class,
() -> {
Webhook.Signature.verifyHeader(payload, sigHeader, secret, 0, null);
});
assertEquals("Unable to extract timestamp and signatures from header", exception.getMessage());
}

@Test
public void testNoSignaturesWithExpectedScheme()
throws SignatureVerificationException, NoSuchAlgorithmException, InvalidKeyException {
Expand Down