fix(security): fail closed own-policy gateway adapters - #45634
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 #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.
Keep the own-policy fail-closed hardening from PR #45444, but still trust WeCom groups.<id>.allow_from because the adapter already checked that sender allowlist before dispatching to gateway auth.
🔎 Lint report:
|
| Rule | Count |
|---|---|
unresolved-attribute |
2 |
First entries
run_agent.py:2891: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`
✅ Fixed issues (1):
| Rule | Count |
|---|---|
invalid-assignment |
1 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`
Unchanged: 5707 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
|
Verification: security-critical fail-closed fix looks solid. Reviewed the full diff across What was checked:
CI note: The single failure is Clean security fix. LGTM. |
|
Verification: security architecture review — LGTM Reviewed the full diff across What was checked:
No issues found. The fix is architecturally sound and the test suite covers the critical decision branches. |
Summary
Own-policy gateway adapters now fail closed when no allowlist is configured, while preserving WeCom per-group sender allowlists.
This salvages #45444 from @Que0x and adds one maintainer follow-up for the WeCom
groups.<group_id>.allow_fromsibling case.Changes
gateway/authz_mixin.py: trust own-policy adapters only for effectiveallowlistpolicy, not defaultopen/ pairing flows.gateway/authz_mixin.py: preserve WeCom group-level sender allowlists as a trusted adapter-enforced restriction even when top-levelgroup_policyisopen.tests/gateway/test_config_driven_access_policy.py: covers fail-closed DM/group defaults, allowlist trust, pairing behavior, and WeCom per-group sender allowlists.Validation
python3 -m py_compile gateway/authz_mixin.py tests/gateway/test_config_driven_access_policy.pyscripts/run_tests.sh tests/gateway/test_config_driven_access_policy.pyAuthorship
Infographic