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.
  • tokenizationId(), cardToken(), cardBrand(), cardLast4(), cardExpMonth(), cardExpYear() on the WebhookEvent record, which keeps a constructor with its previous shape so positional construction still compiles.

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, python and dotnet SDKs verify against. GoldenSignatureTest picks them up automatically; WebhookTest covers the card accessors, a card_token.failed event with no card, and a tampered card_last4. The test helper's signing now mirrors the same block ordering.

There is no Maven on the machine this was written on, so WebhookTest and GoldenSignatureTest were compiled and run directly against JDK 17 with the junit console launcher: 13 tests, all passing. CI runs the full build.

Version 0.2.0 → 0.3.0 across the parent and both modules.

`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. The record keeps a
constructor with its previous shape so positional construction still
compiles. 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.
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