Skip to content

Support restricted keys with webhook signing secrets - #25

Draft
heinrich-paystack wants to merge 1 commit into
PaystackOSS:mainfrom
heinrich-paystack:d5/rk-support
Draft

heinrich-paystack wants to merge 1 commit into
PaystackOSS:mainfrom
heinrich-paystack:d5/rk-support

Conversation

@heinrich-paystack

@heinrich-paystack heinrich-paystack commented Nov 5, 2026 •

Copy link
Copy Markdown

Adds support for restricted keys (rk_) and webhook signing secrets.

A restricted key cannot verify X-Paystack-Signature, which is signed with the secret key. This adds Test and Live "Webhook Signing Secret" settings and verifies the newer Paystack-Signature header with the secret for the mode the event was sent in. Forms that keep using a secret key need no change.

To use a restricted key:

  1. In the Paystack Dashboard, create a restricted key that can use the APIs this plugin calls: transactions (initialize, verify), plans and subscriptions, and paste the rk_test_... or rk_live_... key into the Secret Key field. The plugin sends it as a Bearer token exactly like a secret key.
  2. Under Settings > API Keys & Webhooks, create a webhook signing secret and paste the whsec_... value into the new Webhook Signing Secret field for that mode.

Webhook check order:

  • A signing secret is set and the request has Paystack-Signature: verify it (HMAC-SHA512 with the signing secret over <t>.<raw body>, any v1 entry may match, timestamps older than 5 minutes are rejected). The result is final.
  • Otherwise, the configured key is a secret key (sk_) and the request has X-Paystack-Signature: the existing check, unchanged.
  • Otherwise the webhook is rejected as before.

There is no key-format check in the settings, so rk_ keys are already accepted.

Testing: php tests/run.php on PHP 7.2 and 8.2, 150 passed, 0 failed. New cases cover the signature vector, the 5-minute window, key rotation, malformed headers, each branch of the order above, and get_webhook_event picking the secret for the event's mode. The new cases fail against the previous code. Not tested in a live Gravity Forms install.

🤖 Generated with Claude Code

Add test and live "Webhook Signing Secret" settings and verify the
Paystack-Signature header with them. The X-Paystack-Signature check is
kept for sk_ keys, so existing setups keep working. A restricted key
(rk_) cannot verify X-Paystack-Signature, so it needs the signing secret.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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