mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-05 07:41:39 +00:00
fix(feishu): validate verification token before reflecting url_verification challenge
When FEISHU_VERIFICATION_TOKEN is configured, an unauthenticated remote could previously prove endpoint control by sending a url_verification payload with any attacker-controlled challenge string — the handler reflected the challenge BEFORE running the token check. Move the verification_token check ahead of the url_verification echo so the challenge response is gated on a valid token. Add a regression test covering the wrong-token case. Also fix the stale test_connect_webhook_mode_starts_local_server fixture to set FEISHU_VERIFICATION_TOKEN (post #30746 webhook mode requires a secret). Salvaged from PR #29663 by @m0n3r0 — kept the url_verification reorder and its regression test; dropped the host-conditional weakening of the #30746 secret guard (we want webhook secrets required regardless of bind host, not only on 0.0.0.0/::). Docs updated to call out the gating. Co-authored-by: teknium1 <127238744+teknium1@users.noreply.github.com>
This commit is contained in:
parent
5e6749fbf3
commit
f378f00bfb
3 changed files with 37 additions and 6 deletions
|
|
@ -167,6 +167,7 @@ class TestFeishuAdapterMessaging(unittest.TestCase):
|
|||
"FEISHU_WEBHOOK_HOST": "127.0.0.1",
|
||||
"FEISHU_WEBHOOK_PORT": "9001",
|
||||
"FEISHU_WEBHOOK_PATH": "/hook",
|
||||
"FEISHU_VERIFICATION_TOKEN": "vtok",
|
||||
}, clear=True)
|
||||
def test_connect_webhook_mode_starts_local_server(self):
|
||||
from gateway.config import PlatformConfig
|
||||
|
|
@ -1538,6 +1539,34 @@ class TestAdapterBehavior(unittest.TestCase):
|
|||
self.assertEqual(response.status, 200)
|
||||
adapter._on_message_event.assert_called_once()
|
||||
|
||||
@patch.dict(os.environ, {"FEISHU_VERIFICATION_TOKEN": "expected-token"}, clear=True)
|
||||
def test_url_verification_requires_configured_verification_token(self):
|
||||
"""url_verification must be rejected when token is set but mismatched.
|
||||
|
||||
Regression: previously the challenge was reflected before the token
|
||||
check, so an unauthenticated remote could prove endpoint control by
|
||||
sending an attacker-controlled challenge string.
|
||||
"""
|
||||
from gateway.config import PlatformConfig
|
||||
from gateway.platforms.feishu import FeishuAdapter
|
||||
|
||||
adapter = FeishuAdapter(PlatformConfig())
|
||||
body = json.dumps({
|
||||
"type": "url_verification",
|
||||
"token": "wrong-token",
|
||||
"challenge": "attacker-controlled-challenge",
|
||||
}).encode("utf-8")
|
||||
request = SimpleNamespace(
|
||||
remote="203.0.113.10",
|
||||
content_length=None,
|
||||
headers={},
|
||||
read=AsyncMock(return_value=body),
|
||||
)
|
||||
|
||||
response = asyncio.run(adapter._handle_webhook_request(request))
|
||||
|
||||
self.assertEqual(response.status, 401)
|
||||
|
||||
@patch.dict(os.environ, {}, clear=True)
|
||||
def test_process_inbound_message_uses_event_sender_identity_only(self):
|
||||
from gateway.config import PlatformConfig
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue