Spaces:
Running
Running
fix: SSRF-guard client-supplied chat base_url
Browse files
src/browser_automation_agent/main.py
CHANGED
|
@@ -20,7 +20,7 @@ from rich.panel import Panel
|
|
| 20 |
from . import voice
|
| 21 |
from .browser.manager import SUPPORTED_CHANNELS, browser_manager
|
| 22 |
from .chat_agent import CHAT_ERROR_HINTS, classify_chat_error, run_chat, usable_chat_messages
|
| 23 |
-
from .chat_tools import ChatBrowserSession, ToolError
|
| 24 |
from .client_research import research_client
|
| 25 |
from .config import settings
|
| 26 |
from .context.manager import context_manager
|
|
@@ -1249,6 +1249,29 @@ async def chat_handler(request: web.Request) -> web.Response:
|
|
| 1249 |
if not isinstance(raw_messages, list) or not raw_messages:
|
| 1250 |
return web.json_response({"error": "messages must be a non-empty list"}, status=400)
|
| 1251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1252 |
# Same rule run_chat applies when building its prompt — kept in one place.
|
| 1253 |
messages = ([{"role": "system", "content": system}] if system else []) \
|
| 1254 |
+ usable_chat_messages(raw_messages)
|
|
|
|
| 20 |
from . import voice
|
| 21 |
from .browser.manager import SUPPORTED_CHANNELS, browser_manager
|
| 22 |
from .chat_agent import CHAT_ERROR_HINTS, classify_chat_error, run_chat, usable_chat_messages
|
| 23 |
+
from .chat_tools import ChatBrowserSession, ToolError, check_url
|
| 24 |
from .client_research import research_client
|
| 25 |
from .config import settings
|
| 26 |
from .context.manager import context_manager
|
|
|
|
| 1249 |
if not isinstance(raw_messages, list) or not raw_messages:
|
| 1250 |
return web.json_response({"error": "messages must be a non-empty list"}, status=400)
|
| 1251 |
|
| 1252 |
+
# SSRF guard on the client-supplied base URL (same gate as chat tools): a
|
| 1253 |
+
# hosted backend must not become an open relay into loopback/private
|
| 1254 |
+
# networks. Honored only for BASE_URL_PROVIDERS — for everyone else the
|
| 1255 |
+
# value was already dropped by sanitize_client_base above. The flag
|
| 1256 |
+
# allow_private_networks / DRACULL_ALLOW_PRIVATE_NET keeps localhost dev
|
| 1257 |
+
# working (check_url honors both).
|
| 1258 |
+
if base_url:
|
| 1259 |
+
try:
|
| 1260 |
+
base_url = await check_url(base_url, context="base_url")
|
| 1261 |
+
except ToolError as exc:
|
| 1262 |
+
return web.json_response(
|
| 1263 |
+
{
|
| 1264 |
+
"error": f"base_url rejected: {exc}",
|
| 1265 |
+
"errorKind": "ssrf",
|
| 1266 |
+
"model": model,
|
| 1267 |
+
"hint": (
|
| 1268 |
+
"Point base_url at a public http(s) origin, or clear it "
|
| 1269 |
+
"to use the provider default."
|
| 1270 |
+
),
|
| 1271 |
+
},
|
| 1272 |
+
status=400,
|
| 1273 |
+
)
|
| 1274 |
+
|
| 1275 |
# Same rule run_chat applies when building its prompt — kept in one place.
|
| 1276 |
messages = ([{"role": "system", "content": system}] if system else []) \
|
| 1277 |
+ usable_chat_messages(raw_messages)
|