fix(instagram): enforce webhook signature verification outside production and deduplicate echo events before DB writes
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- postgresql, redis, typescript
- Domain
- backend-api-design, databases, security
Research direction
Read apps/api/src/instagram/instagram.controller.ts around handleWebhook and apps/api/src/instagram/services/instagram-webhook-router.service.ts around processEchoMessagingEvent. Check existing webhook signature and Redis deduplication patterns, then run the relevant API tests. Done means configured secrets trigger signature verification and duplicate echo events return before conversation or follow-up writes.
Written by the indexing model from the issue text.
Description
Problem Description
-
Webhook signature verification is skipped when
NODE_ENV !== 'production':
Inapps/api/src/instagram/instagram.controller.ts(handleWebhook, lines 258-276), Meta'sX-Hub-Signature-256verification is gated behindprocess.env.NODE_ENV === 'production'.
Any staging deployment or misconfigured server whereNODE_ENVis unset or not'production'accepts forged, unauthenticatedPOST /webhooks/instagrampayloads, allowing attackers to inject fake DMs/comments and trigger automations or AI replies. -
Echo webhook mutates state before deduplication:
Inapps/api/src/instagram/services/instagram-webhook-router.service.ts(processEchoMessagingEvent, lines 475-518),conversation.update(deactivating AI and settingautomationPausedUntil = now + 30m) andpendingFollowUp.updateMany(cancelling pending follow-ups) execute beforeredisService.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
POST /webhooks/instagramverifiesX-Hub-Signature-256wheneverINSTAGRAM_APP_SECRETorMETA_APP_SECRETis configured (skipping only if an explicit local dev bypass flag such asALLOW_UNSIGNED_WEBHOOKS=trueis set in non-production).processEchoMessagingEventchecksredisService.reserveWebhookEvent('echo:' + messageMid)first, returning early on duplicates before mutatingconversationorpendingFollowUp.
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
- In
instagram.controller.ts(handleWebhook):- Enforce
X-Hub-Signature-256verification whenever an app secret is configured (instead of gating onNODE_ENV === 'production'), and allow unsigned requests only whenNODE_ENV !== 'production' && process.env.ALLOW_UNSIGNED_WEBHOOKS === 'true'(so local webhook testing tools still work when explicitly enabled).
- Enforce
- In
instagram-webhook-router.service.ts(processEchoMessagingEvent):- Extract
messageMidat the top ofprocessEchoMessagingEventand callredisService.reserveWebhookEvent('echo:' + messageMid)before updatingconversationor cancellingpendingFollowUprecords.
- Extract
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 1
- Avg merge
- 6m
- Merged PRs (30d)
- 27
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sumamakhan761/tryinstance
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#65 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
sumamakhan761/tryinstance#64 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
sumamakhan761/tryinstance#63 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#62 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#60 ·
Maintainers usually reply within 1 day
All issues in sumamakhan761/tryinstance
Similar issues
-
prio:low scope:hud
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OliverRomhagen/vrigstad-joyride#953 ·
Maintainers usually reply within 1 day
-
review-followup
Difficulty 1/5 Under an hour Newbie friendliness 92/100
griffinwork40/agent-afk#5446 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
kacper-szewczyk/Ticknest#346 ·
Maintainers usually reply within 1 day
-
echarts geo: a GeoJSON URL that returns 200 with a body that is not JSON is fetched on each refreshOpenbug plugin/echarts/geo
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Yeachan-Heo/gajae-code#8230 ·
Maintainers usually reply within 1 day