0Pricing
Stripe Payments & SaaS Billing Systems · レッスン

Webhook署名の安全な検証

StripeのWebhook署名を検証し、安全なエンドポイントの実践に従うことで、偽造されたイベントから決済バックエンドを保護します。

「Webhook署名の安全な検証」はCoddyKit上の無料Stripe Payments & SaaS Billing Systemsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはStripe Payments & SaaS Billing Systems学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Stripe Payments & SaaS Billing Systemsコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Why Verify Webhooks?

Your webhook endpoint is public. Without verification, an attacker could POST a fake payment_succeeded event and unlock paid features for free.

The Signing Secret

Each webhook endpoint has a signing secret (starts with whsec_). Stripe uses it to sign every event it sends you.

The Stripe-Signature Header

Every webhook request carries a Stripe-Signature header containing a timestamp and an HMAC signature of the payload.

// Stripe-Signature: t=1700000000,v1=5257a8...

Use the Raw Body

Signature verification needs the exact raw request body. If a framework parses JSON first, the bytes change and verification fails.

app.post('/webhook',
  express.raw({ type: 'application/json' }),
  handler
);

Verifying with the SDK

The Stripe SDK does the HMAC math for you via constructEvent.

function verify(rawBody, sig, secret, stripe) {
  return stripe.webhooks.constructEvent(rawBody, sig, secret);
}

Handling Verification Failure

If verification throws, reject the request with a 400. Never process an unverified event.

function process(ok) {
  if (!ok) return { status: 400, body: 'invalid signature' };
  return { status: 200, body: 'received' };
}
console.log(process(false));

Timestamp Tolerance

The signature includes a timestamp. Stripe rejects events older than a tolerance window to block replay attacks with captured payloads.

Constant-Time Comparison

Under the hood, signatures are compared in constant time to avoid timing attacks. The SDK handles this; never hand-roll a simple equality check.

Respond Fast, Process Later

Acknowledge with 200 quickly, then do heavy work asynchronously. Slow responses make Stripe retry and can cause duplicates.

Keep the Secret Safe

Store the signing secret in environment variables, never in source control. Rotate it if it leaks, using the dashboard.

const secret = process.env.STRIPE_WEBHOOK_SECRET;
console.log(Boolean(secret));

Per-Endpoint Secrets

Each registered endpoint has its own secret. Use the correct one for the URL receiving the event, especially across test and live modes.

Quick Check

Why must you use the raw request body for verification?

Recap

You secured your webhook endpoint:

  • Verify the Stripe-Signature with the signing secret
  • Use the raw body and the SDK constructEvent
  • Reject failures and rely on timestamp tolerance against replays
  • Keep secrets in env vars and respond fast

よくある質問

「Webhook署名の安全な検証」レッスンは無料ですか?

はい。「Webhook署名の安全な検証」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Stripe Payments & SaaS Billing Systemsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Stripe Payments & SaaS Billing Systemsコースには全4レッスンが含まれています。

「Webhook署名の安全な検証」で何を学びますか?

StripeのWebhook署名を検証し、安全なエンドポイントの実践に従うことで、偽造されたイベントから決済バックエンドを保護します。 ブラウザで直接実行するハンズオンコードでStripe Payments & SaaS Billing Systemsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Stripe Payments & SaaS Billing Systemsを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのStripe Payments & SaaS Billing Systemsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「Webhook署名の安全な検証」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このStripe Payments & SaaS Billing Systemsレッスンでコードを書いて実行できますか?

はい。すべてのStripe Payments & SaaS Billing Systemsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 決済手段(トークン)の安全な保存
  2. 強力な顧客認証(SCA)の実装
  3. 開発者向けPCI準拠のベストプラクティス
  4. Webhook署名の安全な検証
← Stripe Payments & SaaS Billing Systemsに戻る