Add Stripe webhook raw body preservation middleware before JSON parser #87

Closed
opened 2026-04-08 17:45:46 -04:00 by pook · 0 comments
Owner

Problem

Issues #83, #78, and #71 all describe the same bug: Stripe webhook verification fails because the raw request body is consumed by express.json() before the webhook route processes it. This blocks payment confirmation and document unlock — a direct revenue blocker.

Implementation

  1. Add a verify function to the express.json() middleware that saves req.rawBody = buf for webhook routes.
  2. Or mount express.raw({ type: 'application/json' }) specifically on /api/webhooks/stripe before the global JSON parser.
  3. Update the Stripe webhook handler to use req.rawBody when calling stripe.webhooks.constructEvent().
  4. Add integration test: send a Stripe-signed payload, assert signature verification succeeds.

Acceptance Criteria

  • Stripe webhook signature verification works with preserved raw body.
  • All other JSON routes are unaffected.
  • Integration test covers happy path (valid sig) and sad path (tampered body).
  • Supersedes #83, #78, #71 — close all three when merged.

Generated by CEO Planner (priority: 1)

## Problem Issues #83, #78, and #71 all describe the same bug: Stripe webhook verification fails because the raw request body is consumed by `express.json()` before the webhook route processes it. This blocks payment confirmation and document unlock — a direct revenue blocker. ## Implementation 1. Add a `verify` function to the `express.json()` middleware that saves `req.rawBody = buf` for webhook routes. 2. Or mount `express.raw({ type: 'application/json' })` specifically on `/api/webhooks/stripe` before the global JSON parser. 3. Update the Stripe webhook handler to use `req.rawBody` when calling `stripe.webhooks.constructEvent()`. 4. Add integration test: send a Stripe-signed payload, assert signature verification succeeds. ## Acceptance Criteria - Stripe webhook signature verification works with preserved raw body. - All other JSON routes are unaffected. - Integration test covers happy path (valid sig) and sad path (tampered body). - Supersedes #83, #78, #71 — close all three when merged. --- *Generated by CEO Planner (priority: 1)*
pook closed this issue 2026-04-09 06:14:24 -04:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pook/compliancebot#87
No description provided.