← Back to PRs

#21893: fix(web): enforce sendPolicy on WhatsApp auto-reply delivery path

by hydro13 open 2026-02-20 14:04 View on GitHub →
channel: whatsapp-web size: M
## Summary Fixes #21824 `resolveSendPolicy()` was being called in all outbound paths (commands, gateway chat, gateway agent) but was **missing** from the WhatsApp WebSocket inbound handler (`process-message.ts`). This meant `sendPolicy` config rules were silently bypassed for WhatsApp auto-replies. ## Changes **`src/web/auto-reply/monitor/process-message.ts`** - Import `resolveSendPolicy` from `../../../sessions/send-policy.js` - Add policy check after echo detection, before ack reaction + dispatch - Channel hardcoded to `'whatsapp'` (this file is WhatsApp-specific) - Returns `false` early when policy is `'deny'`, consistent with other paths **`src/web/auto-reply/monitor/process-message.test.ts`** (new) - 4 tests covering the send-policy gating: 1. Returns `false` and skips dispatch when sendPolicy denies the channel 2. Proceeds to dispatch when policy allows (rule targets different channel) 3. Proceeds to dispatch when no sendPolicy is configured 4. Denies group chat when rule targets `whatsapp` + `chatType: group` ## Known Limitation Per-session `sendPolicy` entry overrides (set directly on individual session entries in the store) are **not** checked in this path — `process-message.ts` does not load session entries. Config-level rules (channel, chatType, keyPrefix matching) work correctly. Per-session overrides can be added in a follow-up if needed. ## Verification ``` npx tsc --noEmit → 0 new errors (2 pre-existing upstream errors in gateway-server-chat-b.e2e.test.ts unchanged) npx vitest run src/web/auto-reply/monitor/ src/sessions/send-policy → 13/13 passed ``` <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds missing `sendPolicy` enforcement to the WhatsApp auto-reply path (`process-message.ts`). The check is positioned after echo detection but before the ack reaction and reply dispatch, matching the gating pattern used in other outbound paths (commands, gateway chat, gateway agent). Hardcodes channel to `'whatsapp'` since this handler is WhatsApp-specific. Test coverage validates all four policy scenarios: deny, allow (different channel rule), allow (no policy), and deny with `chatType` matching. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The change is a straightforward security fix that adds missing policy enforcement. The implementation follows existing patterns from other channels, the placement in the execution flow is correct (after echo detection, before dispatch), and comprehensive tests validate all policy scenarios. No breaking changes or regressions expected. - No files require special attention <sub>Last reviewed commit: 4f3405c</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs