#21893: fix(web): enforce sendPolicy on WhatsApp auto-reply delivery path
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
#14789: fix: per-account dmPolicy ignored in checkInboundAccessControl
by croll83 · 2026-02-12
80.0%
#4390: fix(whatsapp): allow media from allowlisted groups without groupAllow…
by Sarang19114 · 2026-01-30
79.3%
#20626: feat(whatsapp): add linkPreviewPolicy for URL exfiltration protection
by arniesaha · 2026-02-19
78.1%
#19303: Fix WhatsApp internal error leakage + cron.run timeout defaults
by koala73 · 2026-02-17
77.6%
#21889: fix(whatsapp): include outbound DMs in agent context for allowed co...
by mactsk · 2026-02-20
76.7%
#11611: feat: separate group-level allowlist from sender-level command auth...
by thisnick · 2026-02-08
76.6%
#10260: fix(outbound): enforce sendPolicy on system notifications (#6301)
by nu-gui · 2026-02-06
76.0%
#22106: fix(whatsapp): honor selfChatMode override for group mentions
by sportclaw · 2026-02-20
75.9%
#23288: feat(whatsapp): group command gating via commands.allowFrom + sende...
by rodrigoscoelho · 2026-02-22
75.8%
#5665: fix: match group JIDs in groupAllowFrom allowlist
by koala73 · 2026-01-31
75.6%