Commit 3f1997f
Fix NumberFormatException in Webhook.Signature.getTimestamp
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>1 parent 3ae83bb commit 3f1997f
2 files changed
Lines changed: 44 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
186 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
187 | 191 | | |
188 | 192 | | |
189 | 193 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
163 | 202 | | |
164 | 203 | | |
165 | 204 | | |
| |||
0 commit comments