Skip to content

fix(listen): preserve webhook signatures when forwarding#25

Open
bgrcs wants to merge 1 commit into
polarsource:mainfrom
bgrcs:bruno/fix/preserve-webhook-signatures-when-forwarding
Open

fix(listen): preserve webhook signatures when forwarding#25
bgrcs wants to merge 1 commit into
polarsource:mainfrom
bgrcs:bruno/fix/preserve-webhook-signatures-when-forwarding

Conversation

@bgrcs

@bgrcs bgrcs commented Jul 10, 2026

Copy link
Copy Markdown

I was trying out the CLI for local development with hooks and unfortunately ran into a few issues.

Events forwarded by polar listen fail signature verification if my org uses usage based billing. Anything carrying meter data gets rejected by validateEvent from @polar-sh/sdk, but other events are fine:

>> 'product.updated' >> 202 Accepted
>> 'customer.state_changed' >> 403 Forbidden

The main reason this is an issue is because metering payloads have floats like "consumed_units": 0.0, JS stringifies that as 0, and the webhook signature no longer matches for the body bytes.

I changed it to parse the frame with lossless-json, which keeps the original number literals, so the rebuilt body is byte for byte what Polar signed.

Added tests for the reconstruction and also tested against sandbox with a local endpoint verifying via validateEvent: customer.state_changed gets 403 on main and 202 on this branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants