Fix NumberFormatException in Webhook.Signature.getTimestamp#1
Open
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
Open
Fix NumberFormatException in Webhook.Signature.getTimestamp#1devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
Conversation
Webhook.Signature.getTimestamp() calls Long.parseLong() on the raw timestamp value from the signature header without any error handling. If a malformed webhook header arrives with a non-numeric timestamp (e.g. t=abc,v1=sig...), the SDK throws an unhandled NumberFormatException instead of a proper SignatureVerificationException. This change wraps the Long.parseLong() call in a try-catch that returns -1 on NumberFormatException, which the caller (verifyHeader) already handles by throwing a SignatureVerificationException with a descriptive message. Added tests for: - Non-numeric timestamp values - Empty timestamp values - Overflow timestamp values (exceeding Long.MAX_VALUE) Fixes stripe#2149 Co-Authored-By: Jason Kelley <kllyjsn@gmail.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
Webhook.Signature.getTimestamp()callsLong.parseLong()on the raw timestamp value extracted from theStripe-Signatureheader without any error handling. If a malformed header contains a non-numeric, empty, or overflowing timestamp (e.g.t=abc,v1=sig...), the SDK throws an unhandledNumberFormatExceptioninstead of the expectedSignatureVerificationException.After this change, malformed timestamps are handled gracefully using the same code path as a missing timestamp — returning
-1, which the caller (verifyHeader) already checks and converts into a descriptiveSignatureVerificationException.Related: stripe/stripe-java#2149
What?
Long.parseLong()ingetTimestamp()with aNumberFormatExceptioncatch that returns-1(the existing sentinel for "no timestamp found")WebhookTest:testNonNumericTimestamp—t=not_a_numbertestEmptyTimestampValue—t=testOverflowTimestampValue—t=99999999999999999999(exceedsLong.MAX_VALUE)Reviewer Checklist
-1from the catch is consistent —getTimestampalready returns-1at the end when not=key is found, andverifyHeadercheckstimestamp <= 0before throwingSignatureVerificationExceptiongetTimestampisprivate, soverifyHeaderis the only caller — no other code paths are affectedSee Also
Webhook.java:130-135— theverifyHeaderguard that converts-1into aSignatureVerificationExceptionLink to Devin session: https://app.devin.ai/sessions/c1b674151bf44bf5beb6dff50488e9d3
Requested by: @kllyjsn