Repository navigation
feat(whatsapp): owner-aware toolset gating for shared lines #53742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
marcelopaniza
wants to merge
1
commit into
NousResearch:main
Choose a base branch
from
marcelopaniza:feat/whatsapp-owner-toolset-gating
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| """Owner-aware WhatsApp toolset gating (``_whatsapp_owner_tool_gate``). | ||
|
|
||
| A shared / community WhatsApp line otherwise exposes the full agent toolset | ||
| (terminal, code execution, file, ...) to every allowlisted sender. When | ||
| ``whatsapp.nonowner_disabled_toolsets`` is configured, only owners -- the | ||
| ``whatsapp.home_channel`` chat_id or ids in ``whatsapp.owner_users`` -- keep the | ||
| full toolset; everyone else has the configured tools disabled. The feature is | ||
| opt-in (no config -> no behavior change) and fails closed. | ||
| """ | ||
|
|
||
| from types import SimpleNamespace | ||
|
|
||
| from gateway.run import _whatsapp_owner_tool_gate | ||
|
|
||
| OWNER = "178172540747977" | ||
| DROP = ["terminal", "code_execution", "file"] | ||
| CFG = { | ||
| "whatsapp": { | ||
| "home_channel": {"platform": "whatsapp", "chat_id": f"{OWNER}@lid"}, | ||
| "owner_users": ["15551234567"], | ||
| "nonowner_disabled_toolsets": DROP, | ||
| } | ||
| } | ||
|
|
||
|
|
||
| def _src(chat_id): | ||
| return SimpleNamespace(chat_id=chat_id) | ||
|
|
||
|
|
||
| def test_noop_when_feature_unconfigured(): | ||
| cfg = {"whatsapp": {"home_channel": {"chat_id": f"{OWNER}@lid"}}} | ||
| assert _whatsapp_owner_tool_gate(_src("99999@lid"), "whatsapp", cfg, None) is None | ||
|
|
||
|
|
||
| def test_noop_on_other_platforms(): | ||
| assert _whatsapp_owner_tool_gate(_src("99999"), "telegram", CFG, None) is None | ||
|
|
||
|
|
||
| def test_owner_keeps_full_toolset(): | ||
| # home_channel owner, including a device-suffixed LID variant | ||
| assert _whatsapp_owner_tool_gate(_src(f"{OWNER}@lid"), "whatsapp", CFG, None) is None | ||
| assert _whatsapp_owner_tool_gate(_src(f"{OWNER}:12@lid"), "whatsapp", CFG, None) is None | ||
| # explicit owner_users entry (configured as a bare number, sender arrives as a jid) | ||
| assert _whatsapp_owner_tool_gate(_src("15551234567@s.whatsapp.net"), "whatsapp", CFG, None) is None | ||
|
|
||
|
|
||
| def test_non_owner_is_restricted(): | ||
| out = _whatsapp_owner_tool_gate(_src("19998887777@s.whatsapp.net"), "whatsapp", CFG, None) | ||
| assert set(DROP).issubset(set(out)) | ||
|
|
||
|
|
||
| def test_non_owner_preserves_existing_disabled(): | ||
| out = _whatsapp_owner_tool_gate(_src("19998887777@lid"), "whatsapp", CFG, ["moa"]) | ||
| assert "moa" in out | ||
| assert set(DROP).issubset(set(out)) | ||
|
|
||
|
|
||
| def test_fails_closed_when_sender_unknown(): | ||
| # feature active but sender id missing -> restrict, never grant | ||
| out = _whatsapp_owner_tool_gate(SimpleNamespace(), "whatsapp", CFG, None) | ||
| assert set(DROP).issubset(set(out)) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chat_idis the conversation ID, not the sender identity. The WhatsApp adapter builds it fromdata.chatIdand putsdata.senderIdinsource.user_id(plugins/platforms/whatsapp/adapter.py:1360-1365); a home channel that is a group would therefore grant every group member the owner toolset. Matchuser_id_alt/user_idwith the shared WhatsApp alias-resolution helper instead.