feat(wechat): add wechat_allowed_users gating, mirror QQ adapter pattern#97
Open
shaun0927 wants to merge 1 commit intolsdefine:mainfrom
Open
feat(wechat): add wechat_allowed_users gating, mirror QQ adapter pattern#97shaun0927 wants to merge 1 commit intolsdefine:mainfrom
shaun0927 wants to merge 1 commit intolsdefine:mainfrom
Conversation
Closes lsdefine#95. wechatapp.py was the only adapter under frontends/ without an allowed_users gate, while every other adapter (tg, fs, qq, dingtalk, wecom) reads <platform>_allowed_users from mykey.py and rejects unknown senders. Mirror the QQ adapter's pattern (introduced in PR lsdefine#25): - Read 'wechat_allowed_users' via mykeys, normalize via the same 'set comprehension that keeps non-empty stripped strings' idiom. - Use the existing chatapp_common.public_access() helper so the semantics ('empty or ["*"] means public') match the rest of the ecosystem; this preserves backward compatibility for existing setups that have no wechat_allowed_users key. - Drop unauthorized senders with the same '[<Adapter>] unauthorized user: <id>' log message convention used by qq/dingtalk. Add the optional knob to mykey_template.py next to the other allowed_users entries so users can copy the comment block.
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.
Closes #95.
Problem
frontends/wechatapp.pyis the only chat adapter that does not look atan allow-list. Every other adapter under
frontends/reads<platform>_allowed_usersfrommykey.pyand rejects unknown senders:tgapp.pytg_allowed_users(non-empty required)fsapp.pyfs_allowed_usersqqapp.pyqq_allowed_usersdingtalkapp.pydingtalk_allowed_userswecomapp.pywecom_allowed_userswechatapp.pyAfter
python frontends/wechatapp.pyscans the QR code, anyone whomessages the bound personal WeChat account drives the agent — every
tool the agent has (
code_run,file_read,file_write, web control)is reachable to any contact, with no logging or rejection path.
Fix
Mirror the QQ adapter pattern that PR #25 established:
Three deliberate decisions:
chatapp_common.public_access()rather than inliningnot allowed or '*' in allowed, so the semantics stay locked tothe same definition the other adapters use. If
public_accessever changes, wechat picks it up for free.
wechat_allowed_usersgetALLOWED == set(),public_access()returns True, and every message still reaches the agent. This
matches
qq/dingtalk/wecom/fsexactly. (Telegram is thestricter exception that hard-fails on empty; not adopted here to
avoid breaking existing wechat installs without warning.)
qq/dingtalk:[WX] unauthorized user: <uid>, so a user greppingtemp/wechatapp.logsees thesame shape as the other adapters' logs.
mykey_template.pygets the matching# wechat_allowed_users = ['from_user_id']comment line in the existing chat-platform block so the option is
discoverable.
Verification
python -m py_compile frontends/wechatapp.py mykey_template.py— passes.wechat_allowed_usersin mykey) keep workingunchanged because
ALLOWEDis empty →public_access(ALLOWED)is True→ the new check is skipped.
wechat_allowed_users = ['<from_user_id>']get the same allow-list semantics as
qqapp.py(uid must be in the set).Diff size: +8 / -0 across 2 files.