fix(whatsapp): honor dm_policy and group_policy open at the gateway - #37066
Closed
Zyrixtrex wants to merge 1 commit into
Closed
fix(whatsapp): honor dm_policy and group_policy open at the gateway#37066Zyrixtrex wants to merge 1 commit into
Zyrixtrex wants to merge 1 commit into
Conversation
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
The WhatsApp adapter gates inbound access at intake via its documented
config surface (
dm_policy/group_policy/allow_from/group_allow_from),but it never overrode
enforces_own_access_policy. As a result the gateway's_is_user_authorized()re-applied its env-only default-deny: when noWHATSAPP_ALLOWED_USERS(or other allowlist) was set, a message the adapter hadalready authorized (e.g.
dm_policy: open, the documented default) wasdropped again at the gateway — so
whatsapp.dm_policy: openandwhatsapp.group_policy: opendid not actually work, and users saw a silent drop /unexpected pairing prompt.
The fix declares
enforces_own_access_policy = TrueonWhatsAppAdapter. This isthe exact drift-proof contract already used by WeCom, Weixin, Yuanbao, and QQBot
(introduced in #34515): the gateway trusts that an own-policy adapter authorized
the sender at intake and skips the env-only default-deny — while an explicit env
allowlist still takes precedence when configured. WhatsApp has the identical
config surface as those adapters and was simply missed when the flag was added.
No gateway logic changes were needed:
_is_user_authorized()and_get_unauthorized_dm_behavior()already read the flag /dm_policygenerically,so this is a one-line behavioral change plus tests and doc-string updates.
Related Issue
Fixes #
Type of Change
Changes Made
gateway/platforms/whatsapp.py— addenforces_own_access_policyproperty(
-> True) toWhatsAppAdapter, matching the WeCom/Weixin/Yuanbao/QQBot pattern.gateway/platforms/base.py— update theenforces_own_access_policydoc-stringto list WhatsApp among the own-policy adapters.
gateway/run.py— update the_adapter_enforces_own_access_policydoc-string tolist WhatsApp.
tests/gateway/test_config_driven_access_policy.py— add WhatsApp to_OWN_POLICY_PLATFORMS, to the adapter-declares-the-flag parametrization, and tothe env-clearing helper, so the real adapter's flag and the gateway's
trust-without-env-allowlist behavior (DM and group) are both covered.
How to Test
Reproduce (before fix): configure WhatsApp with
dm_policy: openand noWHATSAPP_ALLOWED_USERS/WHATSAPP_ALLOW_ALL_USERS. A DM that the adapteradmits at intake is rejected at the gateway (
_is_user_authorized()returnsFalse→ default-deny), so the user gets a silent drop / pairing promptinstead of a reply.
After fix: the same DM is authorized — the gateway trusts the adapter's
intake decision. Setting
WHATSAPP_ALLOWED_USERSstill restricts access (envallowlist wins), and
dm_policy: allowlist/disabledstill gate correctly.Automated:
All pass (79), including the new WhatsApp parametrizations.
Checklist
Code
fix(scope):,feat(scope):, etc.)tests/gateway/test_config_driven_access_policy.py,test_whatsapp_group_gating.py,test_unauthorized_dm_behavior.py→ 79 passed; full-suite parity is covered by Linux CI)Documentation & Housekeeping
docs/, docstrings) — updatedbase.py/run.pydocstringscli-config.yaml.exampleif I added/changed config keys — N/A (no new config keys)CONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/A (no architecture change)