Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(show): reject dot segments in the vendor proxy path (#2600)

Max72c4359e932d
diff --git a/tests/test_ui_show_pages.py b/tests/test_ui_show_pages.py
index 58008b063..a15f1074e 100644
--- a/tests/test_ui_show_pages.py
+++ b/tests/test_ui_show_pages.py
@@ -13911,6 +13911,110 @@ def test_show_runtime_vendor_asset_proxy_does_not_mark_errors_immutable(monkeypa
assert response.headers["cache-control"] == "no-store"
+def _raw_asgi_request(method: str, raw_path: str, *, host: str, client_ip: str) -> tuple[int, dict[str, str]]:
+ """Drive the ASGI app with an un-normalized path.
+
+ HTTP test clients normalize `..` segments before sending, which would turn a
+ traversal probe into an ordinary request and hide the bug under test.
+ """
+ sent: list[dict] = []
+
+ async def receive():
+ return {"type": "http.request", "body": b"", "more_body": False}
+
+ async def send(message):
+ sent.append(message)
+
+ scope = {
+ "type": "http",
+ "asgi": {"version": "3.0"},
+ "http_version": "1.1",
+ "method": method,
+ "scheme": "https" if host.endswith(".avibe.bot") else "http",
+ "path": urllib.parse.unquote(raw_path),
+ "raw_path": raw_path.encode("ascii"),
+ "root_path": "",
+ "query_string": b"",
+ "headers": [(b"host", host.encode("ascii"))],
+ "client": (client_ip, 50000),
+ "server": (host.split(":")[0], 443),
+ }
+ asyncio.run(app(scope, receive, send))
+ start = next(message for message in sent if message["type"] == "http.response.start")
+ headers = {key.decode("latin-1").lower(): value.decode("latin-1") for key, value in start["headers"]}
+ return start["status"], headers
+
+
+_VENDOR_PROXY_PEERS = (
+ pytest.param("127.0.0.1:5123", "127.0.0.1", id="loopback"),
+ pytest.param("alex.avibe.bot", _remote_peer()["REMOTE_ADDR"], id="remote-public-host"),
+)
+
+
[email protected]("host,client_ip", _VENDOR_PROXY_PEERS)
[email protected]("method", ("GET", "HEAD"))
+ "raw_path",
+ (
+ "/_show-runtime/vendor/../../sessions/ses-target/events",
+ "/_show-runtime/vendor/abc123/../../../sessions/ses-target/messages",
+ "/_show-runtime/vendor/%2e%2e/%2e%2e/sessions/ses-target/events",
+ "/_show-runtime/vendor/%252e%252e/%252e%252e/sessions/ses-target/events",
+ "/_show-runtime/vendor/..%5c..%5csessions/ses-target/events",
+ "/_show-runtime/vendor/../../health",
+ "/_show-runtime/vendor/abc123/.hidden",
+ ),
+)
+def test_show_runtime_vendor_asset_proxy_never_forwards_dot_segments(
+ monkeypatch, tmp_path, raw_path, method, host, client_ip
+):
+ # The vendor route is auth-exempt. If a dot segment reached the runtime, the HTTP
+ # client would normalize it away and the request would land on the runtime's
+ # unauthenticated `/sessions/<id>/...` routes instead of the vendor bundle.
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ _save_config(tmp_path)
+ manager = _FakeShowRuntimeManager(body=b'{"events":[]}', extra_headers={"content-type": "application/json"})
+ set_show_runtime_manager_for_tests(manager)
+ try:
+ status, headers = _raw_asgi_request(method, raw_path, host=host, client_ip=client_ip)
+ finally:
+ set_show_runtime_manager_for_tests(None)
+
+ assert status == 404
+ assert manager.calls == []
+ assert "immutable" not in headers.get("cache-control", "")
+
+
[email protected]("host,client_ip", _VENDOR_PROXY_PEERS)
+def test_show_runtime_vendor_asset_proxy_raw_path_still_forwards_vendor_files(
+ monkeypatch, tmp_path, host, client_ip
+):
+ # Control for the dot-segment test: the same raw ASGI driver reaches the handler
+ # and real vendor file shapes (entry and `chunks/`) are still proxied.
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ _save_config(tmp_path)
+ manager = _FakeShowRuntimeManager(
+ body=b"export const React = {};",
+ extra_headers={"content-type": "text/javascript; charset=utf-8"},
+ )
+ set_show_runtime_manager_for_tests(manager)
+ try:
+ entry_status, _ = _raw_asgi_request(
+ "GET", "/_show-runtime/vendor/39f78992444bc94c/react__jsx-runtime-3CM2R4UI.js", host=host, client_ip=client_ip
+ )
+ chunk_status, _ = _raw_asgi_request(
+ "GET", "/_show-runtime/vendor/39f78992444bc94c/chunks/chunk-ABC123.js", host=host, client_ip=client_ip
+ )
+ finally:
+ set_show_runtime_manager_for_tests(None)
+
+ assert (entry_status, chunk_status) == (200, 200)
+ assert [call[1] for call in manager.calls] == [
+ "/_show-runtime/vendor/39f78992444bc94c/react__jsx-runtime-3CM2R4UI.js",
+ "/_show-runtime/vendor/39f78992444bc94c/chunks/chunk-ABC123.js",
+ ]
+
+
def test_retired_show_runtime_deps_route_is_gone(monkeypatch, tmp_path):
monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
_save_config(tmp_path)
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index dde80643c..b93cb0de6 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -15161,7 +15161,14 @@ async def show_runtime_vendor_asset(vendor_path: str):
`/show/<id>/` surface and the anonymous public `/p/<share>/` surface. We forward
this prefix verbatim (never under a per-session base) and, because the content
hash is in the path, mark successful responses immutable for a year.
+
+ This route is reachable without authentication, so its path must never leave the
+ vendor prefix. Dot segments survive `quote()` and the HTTP client normalizes them
+ before sending, which would rebase the request onto the runtime's unauthenticated
+ session routes. Vendor files never use dot-prefixed segments, so reject them all.
"""
+ if _is_show_page_dot_path(vendor_path):
+ return FastAPIResponse(status_code=404)
runtime_path = f"{_SHOW_RUNTIME_VENDOR_PREFIX}/{quote(vendor_path, safe='/@:-._~')}"
if request._request.url.query:
runtime_path = f"{runtime_path}?{request._request.url.query}"