Skip to content

fix(feishu): adapter declares enforces_own_access_policy so gateway honors group_rules - #56838

Open
shutcode wants to merge 1 commit into
NousResearch:mainfrom
shutcode:fix/feishu-enforces-own-access-policy
Open

fix(feishu): adapter declares enforces_own_access_policy so gateway honors group_rules#56838
shutcode wants to merge 1 commit into
NousResearch:mainfrom
shutcode:fix/feishu-enforces-own-access-policy

Conversation

@shutcode

@shutcode shutcode commented Jul 2, 2026

Copy link
Copy Markdown

Summary

Feishu gates DM/group access at intake via FEISHU_GROUP_POLICY + per-group group_rules.<chat_id>.allowlist (parsed from config.extra). The gateway's env-based FEISHU_ALLOWED_USERS check runs AFTER this.

Problem: when no FEISHU_ALLOWED_USERS env allowlist is configured, the gateway had no way to honor the config-driven group_rules allowlist the adapter already enforced — it default-denied every Feishu group message regardless of group_rules. This is because FeishuAdapter did not declare enforces_own_access_policy = True (unlike WeCom / Weixin / Yuanbao / QQBot / WhatsApp), so the gateway's _is_user_authorized did not trust the adapter's intake-layer decision.

Fix: add enforces_own_access_policy property returning True on FeishuAdapter. The gateway now trusts the adapter's decision when chat_type is group, so group_rules becomes sufficient at the gateway layer without requiring a parallel FEISHU_ALLOWED_USERS env allowlist.

Root cause

Two-layer gating gap:

  1. Adapter layer (_allow_group_message in plugins/platforms/feishu/adapter.py): correctly uses group_rules[chat_id].allowlist — works.
  2. Gateway layer (_is_user_authorized in gateway/authz_mixin.py): checks _adapter_enforces_own_access_policy(platform) via getattr(adapter, "enforces_own_access_policy", False). Feishu returned False → gateway skipped the trust-adapter branch → default-deny for all Feishu group messages.

Changes

  • plugins/platforms/feishu/adapter.py: add enforces_own_access_policy property (returns True) to FeishuAdapter. Mirrors WeCom / Weixin / Yuanbao / QQBot / WhatsApp.
  • tests/gateway/test_config_driven_access_policy.py: extend Feishu coverage — _OWN_POLICY_PLATFORMS, _clear_auth_env (FEISHU_ALLOWED_USERS / FEISHU_ALLOW_ALL_USERS), test_own_policy_adapters_declare_the_flag.

Verification

./venv/bin/pytest tests/gateway/test_config_driven_access_policy.py tests/gateway/test_multiplex_profile_authz.py -q
# 85 passed

Checklist

  • Patch only touches the two relevant files
  • No new core tools / model tool schema changes
  • Prompt caching unaffected (no system prompt / tool schema change)
  • Mirrors existing pattern (WeCom et al.) — no new API surface

…onors group_rules

Feishu gates DM/group access at intake via FEISHU_GROUP_POLICY +
per-group group_rules.<chat_id>.allowlist (parsed from config.extra).
The gateway's env-based FEISHU_ALLOWED_USERS check runs AFTER this; when
no env allowlist is configured, the gateway had no way to honor the
config-driven group_rules allowlist the adapter already enforced -- it
default-denied every Feishu group message regardless of group_rules.

Add enforces_own_access_policy = True on FeishuAdapter, mirroring WeCom /
Weixin / Yuanbao / QQBot / WhatsApp. The gateway now trusts the adapter's
intake-layer decision when the chat_type is group, so group_rules becomes
sufficient at the gateway layer without requiring a parallel
FEISHU_ALLOWED_USERS env allowlist.

Tests: extend test_config_driven_access_policy.py to cover Feishu --
_OWN_POLICY_PLATFORMS, _clear_auth_env (FEISHU_ALLOWED_USERS /
FEISHU_ALLOW_ALL_USERS), and test_own_policy_adapters_declare_the_flag.
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have platform/feishu Feishu / Lark adapter comp/plugins Plugin system and bundled plugins duplicate This issue or pull request already exists labels Jul 2, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #37916 — identical fix: adds the enforces_own_access_policy property (returns True) to FeishuAdapter so the gateway trusts the adapter's config-driven group_rules allowlist instead of default-denying every Feishu group message. #37916 is the earlier open PR; both carry the same parity test. Follows the merged capability-flag mechanism from #34572.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for pursuing the Feishu two-layer admission gap; it is present on current main.

Problems

  • gateway/authz_mixin.py:495-512 evaluates the adapter-wide _group_policy, but Feishu resolves the policy for the actual chat from group_rules[chat_id] first (plugins/platforms/feishu/adapter.py:4305-4313). A static enforces_own_access_policy=True cannot represent that distinction.
  • With FEISHU_GROUP_POLICY=open and a per-chat policy: allowlist, the adapter correctly gates the sender at plugins/platforms/feishu/adapter.py:4326-4327, but the gateway would still see open and deny it. With global allowlist and a per-chat open rule, the inverse mismatch would authorize traffic through the adapter-trust branch.
  • The test addition only extends generic SimpleNamespace flag coverage in tests/gateway/test_config_driven_access_policy.py; it does not exercise Feishu group_rules resolution.

Suggested changes

  • Make the gateway trust decision use Feishu's effective policy for source.chat_id, retaining the existing fail-closed behavior for effective open and other non-allowlist policies.
  • Add real-FeishuAdapter regression cases for the two differing global/per-chat-policy combinations.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have platform/feishu Feishu / Lark adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants