fix(webui): allow switching Default permissions back to Full Access (#6175)

* fix(webui): allow authenticated access mode switching

* refactor(webui): remove constant full access eligibility helpers

* refactor(webui): remove obsolete full access policy parameter

* docs(webui): remove redundant access switching paragraph

* refactor(webui): remove obsolete full access capability
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-12 15:39:33 +08:00
1 parent ae186cb18d
commit 73af08efab
14 files changed
+87 -204

No files matched your search

@@ -2117,7 +2117,7 @@ async def test_remote_webui_scope_allows_access_reduction(
@pytest.mark.asyncio
async def test_remote_access_reduction_rejects_stale_in_flight_message_scope(
async def test_in_flight_message_without_scope_uses_latest_access_mode(
bus: MagicMock,
tmp_path,
monkeypatch,
@@ -2154,10 +2154,6 @@ async def test_remote_access_reduction_rejects_stale_in_flight_message_scope(
"chat_id": chat_id,
"content": "hello",
"webui": True,
"workspace_scope": {
"project_path": str(default_workspace),
"access_mode": "full",
},
},
)
)
@@ -2178,18 +2174,16 @@ async def test_remote_access_reduction_rejects_stale_in_flight_message_scope(
release_hydrate.set()
await message_task
assert sessions.read_session_file(f"websocket:{chat_id}") is None
saved = sessions.read_session_file(f"websocket:{chat_id}")
assert saved["metadata"]["workspace_scope"]["access_mode"] == "restricted"
assert channel.gateway.workspaces.scope_for_session_key(
f"websocket:{chat_id}"
).access_mode == "restricted"
payload = json.loads(message_conn.send.await_args.args[0])
assert payload["event"] == "error"
assert payload["detail"] == "workspace_scope_rejected"
bus.publish_inbound.assert_not_awaited()
bus.publish_inbound.assert_awaited_once()
@pytest.mark.asyncio
async def test_remote_webui_scope_rejects_full_access_for_custom_scope(
async def test_remote_webui_scope_allows_full_access_for_custom_scope(
bus: MagicMock,
tmp_path,
) -> None:
@@ -2220,11 +2214,11 @@ async def test_remote_webui_scope_rejects_full_access_for_custom_scope(
)
payload = json.loads(conn.send.await_args.args[0])
assert payload["event"] == "error"
assert payload["detail"] == "workspace_scope_rejected"
assert payload["reason"] == "full workspace access is unavailable for this connection"
assert payload["chat_id"] == "chat-remote"
assert sessions.read_session_file("websocket:chat-remote") is None
assert payload["event"] == "session_updated"
assert payload["workspace_scope"]["access_mode"] == "full"
assert channel.gateway.workspaces.scope_for_session_key(
"websocket:chat-remote"
).project_path == project.resolve()
@pytest.mark.asyncio
@@ -6621,15 +6615,12 @@ def test_handle_webui_thread_get_does_not_backfill_hidden_subagent_result(
]
@pytest.mark.parametrize("headers,allowed", [
(None, False),
([], False),
({}, False),
({"Host": "localhost:8765"}, True),
({"Host": "remote.example"}, False),
({"Host": "localhost:8765", "X-Forwarded-For": "203.0.113.8"}, False),
@pytest.mark.parametrize("headers", [
{"Host": "localhost:8765"},
{"Host": "remote.example"},
{"Host": "localhost:8765", "X-Forwarded-For": "203.0.113.8"},
])
async def test_full_access_requires_local_handshake(bus, tmp_path, headers, allowed):
async def test_webui_access_mode_can_toggle_back_to_full(bus, tmp_path, headers):
sessions = SessionManager(tmp_path / "sessions")
channel = WebSocketChannel(
{"enabled": True, "allowFrom": ["*"], "host": "127.0.0.1"},
@@ -6639,17 +6630,17 @@ async def test_full_access_requires_local_handshake(bus, tmp_path, headers, allo
)
conn = AsyncMock()
conn.remote_address = ("127.0.0.1", 50123)
conn.request = SimpleNamespace(headers=headers) if headers is not None else None
await channel._dispatch_envelope(conn, "client", {
"type": "set_workspace_scope",
"chat_id": "handshake-scope",
"workspace_scope": {"project_path": str(tmp_path), "access_mode": "full"},
})
result = json.loads(conn.send.await_args.args[0])
if allowed:
conn.request = SimpleNamespace(headers=headers)
for mode in ("full", "restricted", "full"):
conn.send.reset_mock()
await channel._dispatch_envelope(conn, "client", {
"type": "set_workspace_scope",
"chat_id": "handshake-scope",
"workspace_scope": {"project_path": str(tmp_path), "access_mode": mode},
})
result = json.loads(conn.send.await_args.args[0])
assert result["event"] == "session_updated"
assert result["workspace_scope"]["access_mode"] == "full"
else:
assert result["event"] == "error"
assert result["reason"] == "full workspace access is unavailable for this connection"
assert sessions.read_session_file("websocket:handshake-scope") is None
assert result["workspace_scope"]["access_mode"] == mode
assert channel.gateway.workspaces.scope_for_session_key(
"websocket:handshake-scope"
).access_mode == mode
@@ -2531,7 +2531,7 @@ async def test_webui_automation_result_is_authenticated_and_returns_only_selecte
@pytest.mark.asyncio
async def test_remote_new_chat_accepts_server_project_path_but_rejects_remote_full_access(
async def test_remote_new_chat_accepts_server_project_path_and_full_access(
bus: MagicMock, tmp_path: Path
) -> None:
project = tmp_path / "remote-project"
@@ -2585,18 +2585,15 @@ async def test_remote_new_chat_accepts_server_project_path_but_rejects_remote_fu
},
)
rejected = [
json.loads(call.args[0])
for call in connection.send.await_args_list
if json.loads(call.args[0]).get("event") == "error"
]
assert rejected == [
{
"event": "error",
"detail": "workspace_scope_rejected",
"reason": "full workspace access is unavailable for this connection",
}
]
attached = next(
json.loads(call.args[0]) for call in connection.send.await_args_list
if json.loads(call.args[0]).get("event") == "attached"
)
scope = channel.gateway.workspaces.scope_for_session_key(
f"websocket:{attached['chat_id']}"
)
assert scope.project_path == other_project.resolve()
assert scope.access_mode == "full"
@pytest.mark.asyncio
@@ -3656,18 +3653,17 @@ async def test_recovery_mutation_uses_authenticated_websocket_action(bus: MagicM
@pytest.mark.parametrize(
("connection", "headers", "can_use_full_access"),
("connection", "headers"),
[
(_REMOTE, {"Host": "nas.example", "X-Forwarded-For": "203.0.113.42"}, False),
(_LOCAL, {"Host": "nas.example", "X-Forwarded-For": "203.0.113.42"}, False),
(_LOCAL, {"Host": "127.0.0.1:8765"}, True),
(_REMOTE, {"Host": "nas.example", "X-Forwarded-For": "203.0.113.42"}),
(_LOCAL, {"Host": "nas.example", "X-Forwarded-For": "203.0.113.42"}),
(_LOCAL, {"Host": "127.0.0.1:8765"}),
],
)
def test_workspace_payload_separates_remote_project_selection_from_full_access(
def test_workspace_payload_allows_access_selection_for_local_and_remote_clients(
bus: MagicMock,
connection: _FakeConn,
headers: dict[str, str],
can_use_full_access: bool,
) -> None:
channel = _ch(bus)
token = channel.gateway.tokens.issue_api_token(300)
@@ -3681,7 +3677,6 @@ def test_workspace_payload_separates_remote_project_selection_from_full_access(
assert response.status_code == 200
controls = json.loads(response.body.decode())["controls"]
assert controls["can_change_project"] is True
assert controls["can_use_full_access"] is can_use_full_access
assert controls["can_browse_directories"] is True
assert controls["can_resolve_project"] is True
assert controls["can_manage_favorites"] is True
@@ -4178,11 +4173,11 @@ async def test_project_selection_remembers_resolved_path_without_changing_access
assert response.status_code == 200
assert response.json() == {"name": "project", "path": str(project)}
assert channel.gateway.workspaces.default_scope() == scope
payload = channel.gateway.workspaces.payload(can_change_project=True, can_use_full_access=False)
payload = channel.gateway.workspaces.payload(can_change_project=True)
assert payload["recent_projects"] == [{"name": "project", "path": str(project)}]
rejected = await _webui_mutate(channel, "workspace.resolve_project", {"path": str(tmp_path / "missing")}, connection=connection)
assert rejected.status_code == 400
assert channel.gateway.workspaces.payload(can_change_project=True, can_use_full_access=False)["recent_projects"] == payload["recent_projects"]
assert channel.gateway.workspaces.payload(can_change_project=True)["recent_projects"] == payload["recent_projects"]
@pytest.mark.asyncio
@@ -4196,7 +4191,7 @@ async def test_project_favorites_mutation_persists_without_selecting_project(
response = await _webui_mutate(channel, "workspace.favorite", {"path": str(project), "pinned": True}, connection=connection)
assert response.status_code == 200
assert response.json() == {"favorite_projects": [{"name": "pinned", "path": str(project)}]}
payload = channel.gateway.workspaces.payload(can_change_project=True, can_use_full_access=False)
payload = channel.gateway.workspaces.payload(can_change_project=True)
assert payload["favorite_projects"] == response.json()["favorite_projects"]
assert payload["recent_projects"] == []
assert payload["default_scope"]["project_path"] == str(tmp_path)
-6
View File
@@ -164,9 +164,6 @@ class WebUICommandRouter:
def workspace_project_selection_available(self, connection: ServerConnection) -> bool:
return self._http_router.workspace_project_selection_available(connection)
def workspace_full_access_available(self, connection: ServerConnection) -> bool:
return self._http_router.workspace_full_access_available(connection)
async def send_webui_protocol_error(
self,
connection: ServerConnection,
@@ -310,7 +307,6 @@ class WebUICommandRouter:
lambda: self._workspaces.scope_for_new_chat(
envelope,
can_change_project=self.workspace_project_selection_available(connection),
can_use_full_access=self.workspace_full_access_available(connection),
),
)
if scope is None:
@@ -451,7 +447,6 @@ class WebUICommandRouter:
chat_id=chat_id,
chat_running=websocket_turn_wall_started_at(chat_id) is not None,
can_change_project=self.workspace_project_selection_available(connection),
can_use_full_access=self.workspace_full_access_available(connection),
),
chat_id=chat_id,
)
@@ -630,7 +625,6 @@ class WebUICommandRouter:
chat_id=chat_id,
chat_running=websocket_turn_wall_started_at(chat_id) is not None,
can_change_project=self.workspace_project_selection_available(connection),
can_use_full_access=self.workspace_full_access_available(connection),
)
),
chat_id=chat_id,
-23
View File
@@ -175,7 +175,6 @@ def workspaces_payload(
default_workspace: Path,
default_restrict_to_workspace: bool,
can_change_project: bool,
can_use_full_access: bool,
) -> dict[str, Any]:
state = read_webui_workspace_state()
default_access_mode = state["default_access_mode"]
@@ -203,7 +202,6 @@ def workspaces_payload(
],
"controls": {
"can_change_project": can_change_project,
"can_use_full_access": can_use_full_access,
"can_browse_directories": can_change_project,
"can_resolve_project": can_change_project,
"can_manage_favorites": can_change_project,
@@ -302,13 +300,11 @@ class WebUIWorkspaceController:
self,
*,
can_change_project: bool,
can_use_full_access: bool,
) -> dict[str, Any]:
return workspaces_payload(
default_workspace=self._default_workspace,
default_restrict_to_workspace=self._default_restrict_to_workspace,
can_change_project=can_change_project,
can_use_full_access=can_use_full_access,
)
def resolve_project(self, path: object) -> dict[str, str]:
@@ -358,7 +354,6 @@ class WebUIWorkspaceController:
*,
session_key: str | None,
can_change_project: bool,
can_use_full_access: bool,
) -> WorkspaceScope:
current = self.scope_for_session_key(session_key) if session_key else self.default_scope()
raw = envelope.get(WORKSPACE_SCOPE_METADATA_KEY)
@@ -376,18 +371,6 @@ class WebUIWorkspaceController:
"project selection is unavailable for this connection",
status=403,
)
if (
not can_use_full_access
and scope.access_mode == "full"
and (
current.access_mode != "full"
or scope.project_path != current.project_path
)
):
raise WorkspaceScopeError(
"full workspace access is unavailable for this connection",
status=403,
)
return scope
def scope_for_new_chat(
@@ -395,13 +378,11 @@ class WebUIWorkspaceController:
envelope: dict[str, Any],
*,
can_change_project: bool,
can_use_full_access: bool,
) -> WorkspaceScope:
return self.scope_from_envelope(
envelope,
session_key=None,
can_change_project=can_change_project,
can_use_full_access=can_use_full_access,
)
def scope_for_set_request(
@@ -411,7 +392,6 @@ class WebUIWorkspaceController:
chat_id: str,
chat_running: bool,
can_change_project: bool,
can_use_full_access: bool,
) -> WorkspaceScope:
if chat_running:
raise WorkspaceScopeError("chat_running", status=409)
@@ -419,7 +399,6 @@ class WebUIWorkspaceController:
envelope,
session_key=webui_session_key(chat_id),
can_change_project=can_change_project,
can_use_full_access=can_use_full_access,
)
def scope_for_message(
@@ -429,13 +408,11 @@ class WebUIWorkspaceController:
chat_id: str,
chat_running: bool,
can_change_project: bool,
can_use_full_access: bool,
) -> WorkspaceScope:
scope = self.scope_from_envelope(
envelope,
session_key=webui_session_key(chat_id),
can_change_project=can_change_project,
can_use_full_access=can_use_full_access,
)
if (
WORKSPACE_SCOPE_METADATA_KEY in envelope
-24
View File
@@ -446,26 +446,6 @@ class GatewayHTTPHandler:
"""
return True
def workspace_full_access_available(
self,
connection: Any,
headers: Any | None = None,
) -> bool:
"""Return whether this request may opt into Full Access.
A reverse proxy can make a remote browser look like a localhost TCP
peer. Inspect the original browser headers before granting this
capability so proxy-local requests keep the remote restriction.
"""
if self._runtime_surface == "native":
return True
if headers is None:
request = getattr(connection, "request", None)
headers = getattr(request, "headers", None)
if not isinstance(headers, Mapping):
return False
return _is_local_browser_request(connection, headers)
# -- Token management ---------------------------------------------------
def check_api_token(self, request: WsRequest) -> bool:
@@ -1679,10 +1659,6 @@ class GatewayHTTPHandler:
return _http_json_response(
self.workspaces.payload(
can_change_project=self.workspace_project_selection_available(connection),
can_use_full_access=self.workspace_full_access_available(
connection,
request.headers,
),
)
)