Skip to content

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

Closed
hydro13 wants to merge 1 commit intoopenclaw:mainfrom
hydro13:fix/send-policy-whatsapp-inbound
Closed

fix(web): enforce sendPolicy on WhatsApp auto-reply delivery path#21893
hydro13 wants to merge 1 commit intoopenclaw:mainfrom
hydro13:fix/send-policy-whatsapp-inbound

Conversation

@hydro13
Copy link
Copy Markdown
Contributor

@hydro13 hydro13 commented Feb 20, 2026

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 Summary

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.

Confidence Score: 5/5

  • 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

Last reviewed commit: 4f3405c

@openclaw-barnacle openclaw-barnacle bot added channel: whatsapp-web Channel integration: whatsapp-web size: M labels Feb 20, 2026
@Glucksberg
Copy link
Copy Markdown
Contributor

Glucksberg commented Feb 21, 2026

Noticed a possible connection here.

PR #21827 by @rsuk-mb seems to address the same problem.

PR#21827 adds resolveSendPolicy enforcement to the WhatsApp on-message.ts handler, directly fixing the issue that sendPolicy rules are bypassed for WhatsApp auto-replies as reported in #21824.

Both approaches have merit — might be worth coordinating.

Related issue(s): #21824

If any of these links don't look right, let me know and I'll correct them.

@rsuk-mb
Copy link
Copy Markdown

rsuk-mb commented Feb 21, 2026

Hey @hydro13 — we opened #21827 for the same issue before spotting this PR. After comparing the two, your approach of placing the check inside processMessage is cleaner: single insertion point, covers both broadcast and non-broadcast paths, and the chatType handling is slightly more correct (passing the raw value rather than normalizing non-group to undefined).

One minor suggestion: the resolveSendPolicy check currently runs after echo detection, store path resolution, envelope formatting, and session metadata reads (~lines 140-193). Moving it earlier in processMessage would skip that work when the policy denies — small perf win for denied sessions.

Happy to close #21827 in favour of this one.

@hydro13 hydro13 force-pushed the fix/send-policy-whatsapp-inbound branch from 4f3405c to 2ed7f94 Compare February 21, 2026 23:00
hydro13 added a commit to hydro13/openclaw that referenced this pull request Feb 21, 2026
Skip store path, envelope, disk IO, group history, and echo detection
for sessions where send policy denies. No logic change — same gate,
earlier position.

Addresses review suggestion from @rsuk-mb on openclaw#21893.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@openclaw-barnacle openclaw-barnacle bot added the docs Improvements or additions to documentation label Feb 21, 2026
hydro13 added a commit to hydro13/openclaw that referenced this pull request Feb 21, 2026
Skip store path, envelope, disk IO, group history, and echo detection
for sessions where send policy denies. No logic change — same gate,
earlier position.

Addresses review suggestion from @rsuk-mb on openclaw#21893.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@hydro13 hydro13 force-pushed the fix/send-policy-whatsapp-inbound branch from 2ed7f94 to 9ca2ddf Compare February 21, 2026 23:00
@hydro13
Copy link
Copy Markdown
Contributor Author

hydro13 commented Feb 21, 2026

Good catch @rsuk-mb — just pushed the early-exit. The resolveSendPolicy check is now the first thing in processMessage(), before store path resolution, envelope options, readSessionUpdatedAt (disk IO), group history, and echo detection.

Happy to close #21827 in favour of whichever the maintainers prefer.

hydro13 added a commit to hydro13/openclaw that referenced this pull request Feb 21, 2026
Skip store path, envelope, disk IO, group history, and echo detection
for sessions where send policy denies. No logic change — same gate,
earlier position.

Addresses review suggestion from @rsuk-mb on openclaw#21893.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@hydro13 hydro13 force-pushed the fix/send-policy-whatsapp-inbound branch from 9ca2ddf to 3429879 Compare February 21, 2026 23:06
@openclaw-barnacle openclaw-barnacle bot removed the docs Improvements or additions to documentation label Feb 21, 2026
@hydro13
Copy link
Copy Markdown
Contributor Author

hydro13 commented Feb 22, 2026

Thanks @rsuk-mb — good catch on the ordering, and glad the approach looks solid.

Just to confirm: the check is already at the very top of processMessage in the current diff — before storePath, resolveEnvelopeFormatOptions, buildInboundLine, and echo detection. Denied sessions return immediately without touching any of that.

If you can close #21827 in favour of this one, that'd be great. Appreciate the thorough comparison.

hydro13 added a commit to hydro13/openclaw that referenced this pull request Feb 22, 2026
Skip store path, envelope, disk IO, group history, and echo detection
for sessions where send policy denies. No logic change — same gate,
earlier position.

Addresses review suggestion from @rsuk-mb on openclaw#21893.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@hydro13 hydro13 force-pushed the fix/send-policy-whatsapp-inbound branch from 3429879 to aa121b7 Compare February 22, 2026 01:26
rsuk-mb added a commit to rsuk-mb/openclaw that referenced this pull request Feb 24, 2026
…-pick)

Cherry-pick of 49b1212 from fix/enforce-sendpolicy-whatsapp-autoreply.
Temporary local patch until upstream openclaw#21893 merges.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@openclaw-barnacle
Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Feb 28, 2026
@hydro13 hydro13 force-pushed the fix/send-policy-whatsapp-inbound branch from aa121b7 to bfcde24 Compare February 28, 2026 09:56
@hydro13
Copy link
Copy Markdown
Contributor Author

hydro13 commented Feb 28, 2026

Rebased on current main.

@openclaw-barnacle openclaw-barnacle bot removed the stale Marked as stale due to inactivity label Mar 1, 2026
@hydro13
Copy link
Copy Markdown
Contributor Author

hydro13 commented Mar 2, 2026

Rebased on current main. Still relevant and ready for review.

@hydro13
Copy link
Copy Markdown
Contributor Author

hydro13 commented Mar 13, 2026

Closing — fix landed in main via bfcde24 (fix(web): enforce sendPolicy on WhatsApp auto-reply delivery path). Superseded.

@hydro13 hydro13 closed this Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: whatsapp-web Channel integration: whatsapp-web size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sendPolicy not enforced on WhatsApp auto-reply delivery path

3 participants