2020from open_webui .models .users import Users
2121from open_webui .utils .access_control import has_connection_access
2222from open_webui .utils .auth import get_verified_user
23+ from open_webui .utils .terminals import get_terminal_server_url
2324from open_webui .utils .tools import bearer_auth_header , normalize_bearer_token
2425from starlette .background import BackgroundTask
2526
@@ -100,7 +101,7 @@ async def proxy_terminal(
100101 if not await has_connection_access (user , connection , user_group_ids ):
101102 return JSONResponse ({'error' : 'Access denied' }, status_code = 403 )
102103
103- base_url = (connection . get ( 'url' ) or '' ). rstrip ( '/' )
104+ base_url = get_terminal_server_url (connection )
104105 if not base_url :
105106 return JSONResponse ({'error' : 'Terminal server URL not configured' }, status_code = 503 )
106107
@@ -110,11 +111,6 @@ async def proxy_terminal(
110111
111112 target_url = f'{ base_url } /{ safe_path } '
112113
113- # Route through orchestrator policy endpoint if policy_id is set
114- policy_id = connection .get ('policy_id' )
115- if policy_id :
116- target_url = f'{ base_url } /p/{ policy_id } /{ safe_path } '
117-
118114 if request .query_params :
119115 target_url += f'?{ request .query_params } '
120116
@@ -272,16 +268,14 @@ async def ws_terminal(
272268 return
273269 user , connection = result
274270
275- base_url = (connection . get ( 'url' ) or '' ). rstrip ( '/' )
271+ base_url = get_terminal_server_url (connection )
276272 if not base_url :
277273 await ws .close (code = 4003 , reason = 'Terminal server URL not configured' )
278274 return
279275
280276 # Build upstream WebSocket URL (no token in URL)
281277 ws_base = base_url .replace ('https://' , 'wss://' ).replace ('http://' , 'ws://' )
282278
283- # Route through orchestrator policy endpoint if policy_id is set
284- policy_id = connection .get ('policy_id' )
285279 upstream_params = {}
286280 # For orchestrator-backed servers, pass user_id
287281 upstream_params ['user_id' ] = user .id
@@ -292,10 +286,7 @@ async def ws_terminal(
292286 # decode depth) and inject an attacker-chosen user_id ahead of the one appended below.
293287 safe_session_id = urllib .parse .quote (session_id , safe = '' )
294288
295- if policy_id :
296- upstream_url = f'{ ws_base } /p/{ policy_id } /api/terminals/{ safe_session_id } '
297- else :
298- upstream_url = f'{ ws_base } /api/terminals/{ safe_session_id } '
289+ upstream_url = f'{ ws_base } /api/terminals/{ safe_session_id } '
299290 if upstream_params :
300291 upstream_url += f'?{ urllib .parse .urlencode (upstream_params )} '
301292
0 commit comments