fix(instagram): enforce webhook signature verification outside production and deduplicate echo events before DB writes

オープン 初心者向け
#59 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
postgresql, redis, typescript

調査の方向性

apps/api/src/instagram/instagram.controller.ts の handleWebhook 周辺と、apps/api/src/instagram/services/instagram-webhook-router.service.ts の processEchoMessagingEvent 周辺を読んでください。既存の webhook 署名検証と Redis による重複排除のパターンを確認し、関連する API テストを実行してください。設定済みのシークレットによって署名検証が行われ、重複した echo イベントが会話やフォローアップへの書き込み前に返されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

backend bug good first issue
Problem Description
  1. Webhook signature verification is skipped when NODE_ENV !== 'production':
    In apps/api/src/instagram/instagram.controller.ts (handleWebhook, lines 258-276), Meta's X-Hub-Signature-256 verification is gated behind process.env.NODE_ENV === 'production'.
    Any staging deployment or misconfigured server where NODE_ENV is unset or not 'production' accepts forged, unauthenticated POST /webhooks/instagram payloads, allowing attackers to inject fake DMs/comments and trigger automations or AI replies.

  2. Echo webhook mutates state before deduplication:
    In apps/api/src/instagram/services/instagram-webhook-router.service.ts (processEchoMessagingEvent, lines 475-518), conversation.update (deactivating AI and setting automationPausedUntil = now + 30m) and pendingFollowUp.updateMany (cancelling pending follow-ups) execute before redisService.reserveWebhookEvent('echo:' + messageMid) (lines 512-518).
    If Meta retries an echo webhook, the conversation's pause window can be re-extended before deduplication runs.


Expected Behavior
  1. POST /webhooks/instagram verifies X-Hub-Signature-256 whenever INSTAGRAM_APP_SECRET or META_APP_SECRET is configured (skipping only if an explicit local dev bypass flag such as ALLOW_UNSIGNED_WEBHOOKS=true is set in non-production).
  2. processEchoMessagingEvent checks redisService.reserveWebhookEvent('echo:' + messageMid) first, returning early on duplicates before mutating conversation or pendingFollowUp.

Where to Look
  • apps/api/src/instagram/instagram.controller.ts (handleWebhook, lines 258-276)
  • apps/api/src/instagram/services/instagram-webhook-router.service.ts (processEchoMessagingEvent, lines 475-518)

Solution / Implementation Guide
  1. In instagram.controller.ts (handleWebhook):
    • Enforce X-Hub-Signature-256 verification whenever an app secret is configured (instead of gating on NODE_ENV === 'production'), and allow unsigned requests only when NODE_ENV !== 'production' && process.env.ALLOW_UNSIGNED_WEBHOOKS === 'true' (so local webhook testing tools still work when explicitly enabled).
  2. In instagram-webhook-router.service.ts (processEchoMessagingEvent):
    • Extract messageMid at the top of processEchoMessagingEvent and call redisService.reserveWebhookEvent('echo:' + messageMid) before updating conversation or cancelling pendingFollowUp records.
主要言語
TypeScript
スター
2
フォーク
1
平均マージ
6分
マージ済み PR(30日)
27

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

sumamakhan761/tryinstance のほかの issue

sumamakhan761/tryinstance の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。