mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-13 14:37:26 +00:00
Reject malformed CoinPay webhook signatures (#41)
* Reject malformed CoinPay webhook signatures * Fix webhook signature type guard --------- Co-authored-by: Codex Microtask Operator <codex-microtask@example.com>
This commit is contained in:
parent
055cc09d14
commit
e89c10cc80
2 changed files with 2 additions and 1 deletions
|
|
@ -433,6 +433,7 @@ describe("POST /api/webhooks/coinpay", () => {
|
|||
|
||||
expect(verifyCoinPayWebhook(payload, `t=${timestamp},v1=${signature}`, secret)).toBe(true);
|
||||
expect(verifyCoinPayWebhook(payload, `t=${timestamp}, v1=${signature}`, secret)).toBe(true);
|
||||
expect(verifyCoinPayWebhook(payload, `t=${timestamp},v1=${signature}0`, secret)).toBe(false);
|
||||
|
||||
const response = await coinpayWebhook(
|
||||
new NextRequest("http://localhost/api/webhooks/coinpay", {
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ export function verifyCoinPayWebhook(
|
|||
const parts = signatureHeader.split(",").map((part) => part.trim());
|
||||
const timestamp = parts.find((part) => part.startsWith("t="))?.slice(2);
|
||||
const signature = parts.find((part) => part.startsWith("v1="))?.slice(3);
|
||||
if (!timestamp || !signature) {
|
||||
if (!timestamp || !signature || !/^[0-9a-fA-F]{64}$/.test(signature)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue