Skip to content

fix: verify the card-token webhooks, and surface the card they carry - #2

Open
MHJaafar9869 wants to merge 1 commit into
mainfrom
fix/card-token-webhook-signature
Open

MHJaafar9869 wants to merge 1 commit into
mainfrom
fix/card-token-webhook-signature

Conversation

@MHJaafar9869

Copy link
Copy Markdown
Collaborator

What

card_token.created and card_token.failed could not be verified by this SDK, and the card they carry was not readable off the event.

Why

The server signs by opt-out: PaymentIntegrationWebhookJob copies the payload and unset()s a fixed exclusion list before hashing. The tokenisation block it writes for these two events is therefore signed in full — tokenization_id, external_reference, and, once the card is vaulted, card_token, card_brand, card_last4, card_exp_month, card_exp_year.

This SDK signed none of them, so verify() rejected every card-token webhook. Both events are on by default for every integration — a hosted tokenisation has no other way to deliver its token — so this affected anyone saving cards.

How

  • Signed values are rebuilt the way the server assembles them: a block at a time, each gated on its own leading field, and a key keeps the position it was first written at. On an event with no mandate, external_reference is signed after tokenization_id, not at the slot it holds on a subscription event.
  • CARD_TOKEN_CREATED and CARD_TOKEN_FAILED added to WebhookEventType.
  • tokenization_id, card_token, card_brand, card_last4, card_exp_month, card_exp_year on WebhookEvent.

Tests

Two golden vectors — a vaulted card and a failed tokenisation carrying no card — added to golden-signatures.json, the same file the js, php, dotnet and java SDKs verify against. The parity suite picks them up automatically; explicit cases cover the card fields, a tampered card_last4, and that the mandate-slot ordering of external_reference does not verify.

34 tests pass. Version 0.2.0 → 0.3.0.

`card_token.created` and `card_token.failed` were unverifiable. The server
signs by opt-out — PaymentIntegrationWebhookJob copies the payload and unsets
a fixed exclusion list before hashing — so the tokenisation block it writes
for these two events is signed in full: `tokenization_id`,
`external_reference`, and, once the card is vaulted, `card_token`,
`card_brand`, `card_last4`, `card_exp_month` and `card_exp_year`. This SDK
signed none of them, so every card-token webhook failed verification. Both
events are on by default for every integration, because a hosted tokenisation
has no other way to deliver its token, so this reached anyone saving cards.

The signed values are now rebuilt the way the server assembles them, a block
at a time: a block is gated on its own leading field, and a key keeps the
position it was first written at. That ordering is the whole of it — the
signature is a separator-less concatenation, and on an event with no mandate
`external_reference` is signed after `tokenization_id`, not at the slot it
holds on a subscription event.

The card is also readable off WebhookEvent now. Two golden vectors cover the
vaulted card and a failed tokenisation that carries no card at all; they are
the same vectors the other SDKs verify against.

This branch has not been deployed

No deployments
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.

1 participant