fix(security): fail closed when an own-policy gateway adapter has no allowlist - #45444
fix(security): fail closed when an own-policy gateway adapter has no allowlist#45444Que0x wants to merge 1 commit into
Conversation
…allowlist
Own-policy adapters (WhatsApp, WeCom, Weixin, QQBot, Yuanbao) default dm_policy/group_policy to "open", which forwards every sender. The gateway's adapter-trust shortcut in _is_user_authorized blanket-trusted those platforms when no env allowlist was set, so an operator who enabled one with only credentials authorized the entire external network -- the fail-open SECURITY.md section 2.6 forbids ("an allowlist is required for every enabled network-exposed adapter").
Trust the adapter only when its effective policy for the chat type is an actual "allowlist" restriction (the case NousResearch#34515 was protecting). "open"/"pairing"/anything else falls through to default-deny, where {PLATFORM}_ALLOW_ALL_USERS / GATEWAY_ALLOW_ALL_USERS and the pairing flow remain the explicit opt-ins.
|
Reviewed the full diff — this is a clean and well-structured security fix. What it does: Changes the Verified:
No issues found. LGTM. |
|
Verification review — LGTM. Reviewed the full diff of this security fix. Key observations:
|
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Security fix: own-policy gateway adapters with dm_policy: open or group_policy: open (the defaults) were previously trusted at the gateway level, constituting a fail-open. The fix changes the trust logic to only accept allowlist policy as authorization signal — open, pairing, and disabled all fall through to the default-deny path.
Security
- Before: adapters defaulting to
dm_policy: openforwarded every sender but were trusted by the gateway, silently allowing the whole external network (SECURITY.md violation) - After: only
dm_policy: allowlist/group_policy: allowlistis trusted;open→ default-deny; explicit opt-in still viaGATEWAY_ALLOW_ALL_USERS/{PLATFORM}_ALLOW_ALL_USERS
Code Quality
- New
_adapter_group_policy()method mirrors_adapter_dm_policy()for group/forum/channel traffic - Well-documented with SECURITY.md §2.6 cross-references throughout
- New tests cover: allowlist authorized, open DM denied, default open fails closed, group allowlist trusted, group open denied — all parametrized across all own-policy platforms
Looks Good
- Clean, well-scoped security fix with comprehensive test coverage
What
Own-policy gateway adapters (WhatsApp, WeCom, Weixin, QQBot, Yuanbao)
default
dm_policy/group_policytoopen, which forwards everysender. The adapter-trust shortcut in
_is_user_authorizedthenblanket-trusted those platforms whenever no env allowlist was set, so
enabling one with only credentials authorized the entire external
network.
This is the fail-open SECURITY.md §2.6 names a code bug: "an allowlist
is required for every enabled network-exposed adapter ... code paths
that fail open when no allowlist is configured are code bugs."
Fix
Trust the adapter only when its effective policy for the chat type is
an actual
allowlistrestriction (the config-only allowlist case#34515 protects).
open/pairing/ anything else falls through todefault-deny, where
{PLATFORM}_ALLOW_ALL_USERS,GATEWAY_ALLOW_ALL_USERSand the pairing flow stay the explicitopt-ins to broader access.
gateway/authz_mixin.py— allowlist-only trust; new_adapter_group_policyhelper for group/forum/channel traffic.gateway/platforms/base.py— docstring corrected.Config-only
dm_policy: allowlist/allow_fromkeeps working; onlythe silent
openfail-open is removed.Tests
scripts/run_tests.sh tests/gateway/test_config_driven_access_policy.pyopen+ no-allowlist →authorized (they encoded the fail-open) into fail-closed assertions.
openDM, explicitopenDM, andopengroup all deny without an allowlist;allowlistpolicy staystrusted (DM + group).
Results
test_config_driven_access_policy.pytests/gateway/