Fix webhook signature verification for payloads containing special characters
評価
調査の方向性
Utils.verifyWebhookSignature から始めて、HMAC 検証の前に現在の String ペイロードと webhook secret がどのように変換されているかを調べます。特殊文字またはマルチバイト文字を含むペイロードで Scala Play のシナリオを再現し、その後、raw byte 入力と UTF-8 の明示的な処理によって期待される署名が生成されることを、ASCII として有効な入力の動作を変更せずに確認します。
索引モデルが issue の本文から書いたものです。
説明
In certain environments, such as Scala Play 2.8/2.9, Utils.verifyWebhookSignature may return false for valid webhook requests when the payload contains special characters or multi-byte text. The issue appears to come from the SDK accepting only a String, while framework-level parsing can alter the raw request body before verification.
Problem
Utils.verifyWebhookSignature currently accepts only a String.
This issue is especially likely when a user uses a framework such as Play to read the request body into a String before passing it to the SDK, since webhook validation is safest when performed on the raw body bytes rather than a parsed or re-encoded string.
Reproduction
- Receive a Razorpay webhook containing special characters or multi-byte characters in fields such as customer name or notes.
- Parse the HTTP body as a
Stringin Scala Play. - Pass the resulting string to
Utils.verifyWebhookSignature(...). - Observe that the method returns
falseeven though the webhook is valid.
Proposed Fix
1. Add an overload that accepts raw bytes
Introduce a new method in Utils that accepts byte[] so developers can pass the raw request body directly:
public static boolean verifyWebhookSignature(byte[] payload, String expectedSignature, String webhookSecret) throws RazorpayException {
// Use raw bytes directly to avoid encoding issues
}
2. Use UTF-8 explicitly in string-based hashing
Update the existing implementation so string payloads are always converted using UTF-8:
// Current
byte[] hash = sha256_HMAC.doFinal(payload.getBytes());
// Proposed
byte[] hash = sha256_HMAC.doFinal(payload.getBytes(UTF-8));
//Similar charset as used for encoding the webhook secret to bytes
This makes the behavior deterministic across environments and avoids platform-dependent failures.
Why This Matters
Razorpay’s webhook validation flow depends on the exact payload used to generate the HMAC signature. Any transformation of the request body — including charset conversion, normalization, or parsing into a framework-specific string type — can break verification. A byte-array overload would let developers verify the webhook against the exact raw request body, which is the safest approach for cryptographic checks.
Related Reference
A similar webhook signature verification issue has already been documented here Python SDK, Issue 65, where valid webhook signatures failed to verify in real-world setups.
I am happy to submit a PR for this if the approach is approved.
- 主要言語
- Java
- スター
- 75
- フォーク
- 83
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
razorpay/razorpay-java のほかの issue
-
Document multipart serializer mislabels MIME and emits duplicate file parts対応中かも @u7k4rs6 が 40 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
razorpay/razorpay-java#365 ·
-
Fix response parsing in shaded builds and update test infrastructure for modern JDKs対応中かも @maheshshinde9100 が 270 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
razorpay/razorpay-java#363 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
razorpay/razorpay-java#341 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
razorpay/razorpay-java#340 · コメント 3 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
razorpay/razorpay-java#337 ·
razorpay/razorpay-java の issue をすべて見る
似ている issue
-
agent:working bug follow-up lane:auto
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Sanne/incus-spawn#1765 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Mend: dependency security vulnerability untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100
opensearch-project/data-prepper#7219 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
PaperMC/docs#824 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信