Skip to content

The agent that grows with you

fix(bot-screen): a display ticket is not a gateway login on /api/ws

teknium1223ad499a98d
diff --git a/hermes_cli/web_server_chat.py b/hermes_cli/web_server_chat.py
index 047bc867afb..7196a3254f4 100644
--- a/hermes_cli/web_server_chat.py
+++ b/hermes_cli/web_server_chat.py
@@ -270,7 +270,12 @@ def _ws_auth_reason(ws: "WebSocket") -> tuple[Optional[str], str]:
return "no_credential", "none"
try:
- _stamp_identity(consume_ticket(ticket))
+ info = consume_ticket(ticket)
+ if info.get("provider") == "bot-desktop":
+ # A display ticket admits one RFB bridge on /api/display/ws (a watch-only
+ # capability handed to a screen viewer); it must not double as a login here.
+ raise TicketInvalid("display ticket presented as a gateway login")
+ _stamp_identity(info)
if protocol_ticket:
# Select only the stable public protocol during accept. The
# ticket-bearing protocol is a credential and must never be
diff --git a/tests/hermes_cli/test_ws_auth_display_ticket.py b/tests/hermes_cli/test_ws_auth_display_ticket.py
new file mode 100644
index 00000000000..626f2c106c3
--- /dev/null
+++ b/tests/hermes_cli/test_ws_auth_display_ticket.py
@@ -0,0 +1,37 @@
+"""A Bot Desktop display ticket admits one RFB bridge on ``/api/display/ws`` — it must never pass as a
+full login on ``/api/ws`` (the reverse of ``test_display_ws_ticket``, which refuses gateway tickets there)."""
+
+from __future__ import annotations
+
+from types import SimpleNamespace
+
+import pytest
+
+from hermes_cli import web_server
+import hermes_cli.web_server_chat as _web_server_chat
+from hermes_cli.dashboard_auth.ws_tickets import _reset_for_tests, mint_ticket
+
+
+def gated_state():
+ _reset_for_tests()
+ prev = getattr(web_server.app.state, "auth_required", None)
+ web_server.app.state.auth_required = True
+ yield
+ web_server.app.state.auth_required = prev
+ _reset_for_tests()
+
+
+def _ws(ticket: str):
+ return SimpleNamespace(
+ query_params={"ticket": ticket}, headers={},
+ client=SimpleNamespace(host="203.0.113.9"), url=SimpleNamespace(path="/api/ws"))
+
+
+def test_display_ticket_is_refused_as_a_gateway_login(gated_state):
+ ticket = mint_ticket(user_id="display:v", provider="bot-desktop",
+ extra={"hermes_home": "/srv/hermes/bot-a", "viewer_id": "v"})
+ ws = _ws(ticket)
+ reason, _credential = _web_server_chat._ws_auth_reason(ws)
+ assert reason == "ticket_invalid"
+ assert not hasattr(ws, "_hermes_auth_identity")