fix(webui): support remote project paths and honor picker capabilities (#5673)
* fix(webui): honor remote workspace picker capability * feat(webui): allow remote project path selection * test(webui): isolate native picker availability from host platform
This commit is contained in:
1 parent
15976ac559
commit
ddd6b302c9
9 files changed
+358
-44
No files matched your search
@@ -151,8 +151,11 @@ class WebUICommandRouter:
|
||||
self.request_operations: dict[str, WebUIRequestOperation] = {}
|
||||
self.request_locks: dict[ServerConnection, asyncio.Lock] = {}
|
||||
|
||||
def workspace_controls_available(self, connection: ServerConnection) -> bool:
|
||||
return self._http_router.workspace_controls_available(connection)
|
||||
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,
|
||||
@@ -296,7 +299,8 @@ class WebUICommandRouter:
|
||||
connection,
|
||||
lambda: self._workspaces.scope_for_new_chat(
|
||||
envelope,
|
||||
controls_available=self.workspace_controls_available(connection),
|
||||
can_change_project=self.workspace_project_selection_available(connection),
|
||||
can_use_full_access=self.workspace_full_access_available(connection),
|
||||
),
|
||||
)
|
||||
if scope is None:
|
||||
@@ -436,7 +440,8 @@ class WebUICommandRouter:
|
||||
envelope,
|
||||
chat_id=chat_id,
|
||||
chat_running=websocket_turn_wall_started_at(chat_id) is not None,
|
||||
controls_available=self.workspace_controls_available(connection),
|
||||
can_change_project=self.workspace_project_selection_available(connection),
|
||||
can_use_full_access=self.workspace_full_access_available(connection),
|
||||
),
|
||||
chat_id=chat_id,
|
||||
)
|
||||
@@ -580,7 +585,8 @@ class WebUICommandRouter:
|
||||
envelope,
|
||||
chat_id=chat_id,
|
||||
chat_running=websocket_turn_wall_started_at(chat_id) is not None,
|
||||
controls_available=self.workspace_controls_available(connection),
|
||||
can_change_project=self.workspace_project_selection_available(connection),
|
||||
can_use_full_access=self.workspace_full_access_available(connection),
|
||||
)
|
||||
),
|
||||
chat_id=chat_id,
|
||||
|
||||
+39
-14
@@ -151,7 +151,8 @@ def workspaces_payload(
|
||||
*,
|
||||
default_workspace: Path,
|
||||
default_restrict_to_workspace: bool,
|
||||
controls_available: bool,
|
||||
can_change_project: bool,
|
||||
can_use_full_access: bool,
|
||||
folder_picker_available: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
default_access_mode = read_webui_default_access_mode()
|
||||
@@ -169,8 +170,8 @@ def workspaces_payload(
|
||||
"default_access_mode": default_access_mode,
|
||||
"default_scope": default_scope.payload(),
|
||||
"controls": {
|
||||
"can_change_project": controls_available,
|
||||
"can_use_full_access": controls_available,
|
||||
"can_change_project": can_change_project,
|
||||
"can_use_full_access": can_use_full_access,
|
||||
"can_pick_folder": folder_picker_available,
|
||||
},
|
||||
}
|
||||
@@ -254,13 +255,15 @@ class WebUIWorkspaceController:
|
||||
def payload(
|
||||
self,
|
||||
*,
|
||||
controls_available: bool,
|
||||
can_change_project: bool,
|
||||
can_use_full_access: bool,
|
||||
folder_picker_available: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
return workspaces_payload(
|
||||
default_workspace=self._default_workspace,
|
||||
default_restrict_to_workspace=self._default_restrict_to_workspace,
|
||||
controls_available=controls_available,
|
||||
can_change_project=can_change_project,
|
||||
can_use_full_access=can_use_full_access,
|
||||
folder_picker_available=folder_picker_available,
|
||||
)
|
||||
|
||||
@@ -269,7 +272,8 @@ class WebUIWorkspaceController:
|
||||
envelope: dict[str, Any],
|
||||
*,
|
||||
session_key: str | None,
|
||||
controls_available: bool,
|
||||
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)
|
||||
@@ -282,20 +286,37 @@ class WebUIWorkspaceController:
|
||||
default_restrict_to_workspace=self._default_restrict_to_workspace,
|
||||
source_channel=_WEBUI_SCOPE_CHANNEL,
|
||||
)
|
||||
if not controls_available and not _scope_change_is_non_escalating(current, scope):
|
||||
raise WorkspaceScopeError("workspace controls are localhost-only", status=403)
|
||||
if not can_change_project and not _scope_change_is_non_escalating(current, scope):
|
||||
raise WorkspaceScopeError(
|
||||
"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(
|
||||
self,
|
||||
envelope: dict[str, Any],
|
||||
*,
|
||||
controls_available: bool,
|
||||
can_change_project: bool,
|
||||
can_use_full_access: bool,
|
||||
) -> WorkspaceScope:
|
||||
return self.scope_from_envelope(
|
||||
envelope,
|
||||
session_key=None,
|
||||
controls_available=controls_available,
|
||||
can_change_project=can_change_project,
|
||||
can_use_full_access=can_use_full_access,
|
||||
)
|
||||
|
||||
def scope_for_set_request(
|
||||
@@ -304,14 +325,16 @@ class WebUIWorkspaceController:
|
||||
*,
|
||||
chat_id: str,
|
||||
chat_running: bool,
|
||||
controls_available: bool,
|
||||
can_change_project: bool,
|
||||
can_use_full_access: bool,
|
||||
) -> WorkspaceScope:
|
||||
if chat_running:
|
||||
raise WorkspaceScopeError("chat_running", status=409)
|
||||
return self.scope_from_envelope(
|
||||
envelope,
|
||||
session_key=webui_session_key(chat_id),
|
||||
controls_available=controls_available,
|
||||
can_change_project=can_change_project,
|
||||
can_use_full_access=can_use_full_access,
|
||||
)
|
||||
|
||||
def scope_for_message(
|
||||
@@ -320,12 +343,14 @@ class WebUIWorkspaceController:
|
||||
*,
|
||||
chat_id: str,
|
||||
chat_running: bool,
|
||||
controls_available: bool,
|
||||
can_change_project: bool,
|
||||
can_use_full_access: bool,
|
||||
) -> WorkspaceScope:
|
||||
scope = self.scope_from_envelope(
|
||||
envelope,
|
||||
session_key=webui_session_key(chat_id),
|
||||
controls_available=controls_available,
|
||||
can_change_project=can_change_project,
|
||||
can_use_full_access=can_use_full_access,
|
||||
)
|
||||
if (
|
||||
WORKSPACE_SCOPE_METADATA_KEY in envelope
|
||||
|
||||
@@ -407,8 +407,36 @@ class GatewayHTTPHandler:
|
||||
mcp_oauth_redirect_uri=self._mcp_oauth_redirect_uri,
|
||||
)
|
||||
|
||||
def workspace_controls_available(self, connection: Any) -> bool:
|
||||
return self._runtime_surface == "native" or _is_localhost(connection)
|
||||
def workspace_project_selection_available(self, connection: Any) -> bool:
|
||||
"""Return whether an authenticated WebUI may submit a server path.
|
||||
|
||||
Project paths are interpreted by the gateway, not by the browser. The
|
||||
WebUI route and WebSocket handshake already authenticate the caller,
|
||||
so remote clients can use the manual server-path picker as well.
|
||||
"""
|
||||
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):
|
||||
# Lightweight in-process test connections do not carry a
|
||||
# handshake request. Real WebSocket connections do.
|
||||
return _is_localhost(connection)
|
||||
return _is_local_browser_request(connection, headers)
|
||||
|
||||
def workspace_folder_picker_available(
|
||||
self,
|
||||
@@ -1439,7 +1467,11 @@ class GatewayHTTPHandler:
|
||||
return _http_error(401, "Unauthorized")
|
||||
return _http_json_response(
|
||||
self.workspaces.payload(
|
||||
controls_available=self.workspace_controls_available(connection),
|
||||
can_change_project=self.workspace_project_selection_available(connection),
|
||||
can_use_full_access=self.workspace_full_access_available(
|
||||
connection,
|
||||
request.headers,
|
||||
),
|
||||
folder_picker_available=self.workspace_folder_picker_available(
|
||||
connection,
|
||||
request,
|
||||
|
||||
Reference in new issue
Block a user