fix(webhook): validate the payment id and never log it #151

Sammanfogat
supernaut sammanfogade 2 incheckningar från fix/139-webhook-validate-id in i main 2026-10-12 14:24:53 +00:00
Ägare

What

POST /webhooks/mollie now accepts only ids matching ^tr_[A-Za-z0-9]+$. Anything else gets 200 with no Mollie call.

parseCallback returns no events when payments.get answers 404, so an unknown id also gets 200, as the Mollie docs recommend. Only that call is covered. A 404 on the refund listing for a real payment still fails and Mollie retries.

The failure log is now the fixed line [webhook] failed. The raw id and the SDK message are never logged. A crafted id can no longer forge a line that matches the BillingReconcileManualReview alert.

Other failures still return 500 so Mollie retries.

Tests

  • src/server.test.ts: invalid ids (forged log text, tr_, tr_a/b, pay_1) return 200 and make no provider call. A provider failure returns 500 and the log line has neither the id nor the SDK message.
  • src/provider/mollie.test.ts: a 404 from payments.get, built with the SDK's ApiError, gives no events.

All fail without the fix. pnpm lint, pnpm typecheck and pnpm test pass.

Closes #139

## What `POST /webhooks/mollie` now accepts only ids matching `^tr_[A-Za-z0-9]+$`. Anything else gets 200 with no Mollie call. `parseCallback` returns no events when `payments.get` answers 404, so an unknown id also gets 200, as the Mollie docs recommend. Only that call is covered. A 404 on the refund listing for a real payment still fails and Mollie retries. The failure log is now the fixed line `[webhook] failed`. The raw id and the SDK message are never logged. A crafted id can no longer forge a line that matches the `BillingReconcileManualReview` alert. Other failures still return 500 so Mollie retries. ## Tests - `src/server.test.ts`: invalid ids (forged log text, `tr_`, `tr_a/b`, `pay_1`) return 200 and make no provider call. A provider failure returns 500 and the log line has neither the id nor the SDK message. - `src/provider/mollie.test.ts`: a 404 from `payments.get`, built with the SDK's `ApiError`, gives no events. All fail without the fix. `pnpm lint`, `pnpm typecheck` and `pnpm test` pass. Closes #139
supernaut lade till 2 incheckningar 2026-10-12 14:09:51 +00:00
Accept only ids matching ^tr_[A-Za-z0-9]+$ and answer 200 without a
provider call for anything else. Map a Mollie 404 to 200. Log a fixed
line with the status code, not the id or the SDK message.

Closes #139
fix(webhook): treat only a payment 404 as an unknown id
Alla kontroller lyckades
ci / ci (pull_request) Successful in 2m13s
2336730e07
Catch the 404 around payments.get in parseCallback and return no
events, so a 404 on the refund listing still surfaces. Drop the status
lookup in the server and log a fixed line.
supernaut schemalade den här ändringsförfrågan för automatisk sammanfogning när alla kontroller lyckas 2026-10-12 14:10:21 +00:00
supernaut avbröt automatisk sammanfogning av den här ändringsförfrågan när alla kontroller lyckas 2026-10-12 14:12:18 +00:00
supernaut sammanfogade incheckning 836642da91 till main 2026-10-12 14:24:53 +00:00
supernaut tog bort grenen fix/139-webhook-validate-id 2026-10-12 14:24:53 +00:00
Logga in för att delta i denna konversation.
Inga granskare
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Förfallodatumet är ogiltigt eller utanför gränserna. Använd formatet "åååå-mm-dd".

Inget förfallodatum satt.

Beroenden

Inga beroenden satta

Referens
bitborg/bitborg-payment!151
Ingen beskrivning angiven.