Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

fix: keep dashboard route boundaries out of upstream passthrough (#3324)

Matt Van Horn213b37158fb9
diff --git a/headroom/proxy/server.py b/headroom/proxy/server.py
index a063fb0c8..d72400d49 100644
--- a/headroom/proxy/server.py
+++ b/headroom/proxy/server.py
@@ -3842,6 +3842,12 @@ def create_app(config: ProxyConfig | None = None) -> FastAPI:
# check_dir=False keeps a missing assets directory from aborting proxy
# startup: the dashboard JS 404s, but proxying itself still works.
+ @app.get("/dashboard/static", include_in_schema=False)
+ @app.get("/dashboard/static/", include_in_schema=False)
+ async def dashboard_static_directory():
+ """Keep the static directory boundary out of upstream passthrough."""
+ return PlainTextResponse("Not Found", status_code=404)
+
app.mount(
"/dashboard/static",
StaticFiles(directory=STATIC_DIR, check_dir=False),
@@ -3849,6 +3855,7 @@ def create_app(config: ProxyConfig | None = None) -> FastAPI:
)
@app.get("/dashboard", response_class=HTMLResponse)
+ @app.get("/dashboard/", response_class=HTMLResponse, include_in_schema=False)
async def dashboard():
"""Serve the Headroom dashboard UI."""
return get_dashboard_html()
diff --git a/tests/test_dashboard_static_assets.py b/tests/test_dashboard_static_assets.py
index 30ee855cf..d0b4cadb4 100644
--- a/tests/test_dashboard_static_assets.py
+++ b/tests/test_dashboard_static_assets.py
@@ -7,10 +7,13 @@ Windows machines. Tailwind/htmx/alpine are vendored and served locally instead.
from __future__ import annotations
+from unittest.mock import AsyncMock, patch
+
import pytest
pytest.importorskip("fastapi")
+from fastapi.responses import Response # noqa: E402
from fastapi.testclient import TestClient # noqa: E402
from headroom.dashboard import get_dashboard_html, get_settings_html # noqa: E402
@@ -20,7 +23,8 @@ ASSETS = ["tailwind.min.js", "htmx.min.js", "alpine.min.js"]
@pytest.fixture
-def client():
+def client(monkeypatch):
+ monkeypatch.setenv("HEADROOM_SKIP_UPSTREAM_CHECK", "1")
app = create_app(
ProxyConfig(
optimize=False,
@@ -28,12 +32,23 @@ def client():
rate_limit_enabled=False,
cost_tracking_enabled=False,
log_requests=False,
+ http2=False,
)
)
with TestClient(app) as c:
yield c
+def passthrough(client):
+ with patch.object(
+ client.app.state.proxy,
+ "handle_passthrough",
+ new=AsyncMock(return_value=Response("upstream", status_code=418)),
+ ) as handler:
+ yield handler
+
+
@pytest.mark.parametrize("html", [get_dashboard_html(), get_settings_html()])
def test_templates_reference_no_cdn(html: str):
assert "unpkg.com" not in html
@@ -41,10 +56,35 @@ def test_templates_reference_no_cdn(html: str):
@pytest.mark.parametrize("asset", ASSETS)
-def test_asset_is_served(client, asset: str):
+def test_asset_is_served(client, passthrough, asset: str):
resp = client.get(f"/dashboard/static/{asset}")
assert resp.status_code == 200, resp.text
assert len(resp.content) > 10_000
+ passthrough.assert_not_called()
+
+
+def test_dashboard_trailing_slash_is_served_locally(client, passthrough):
+ resp = client.get("/dashboard/")
+
+ assert resp.status_code == 200
+ assert resp.text == get_dashboard_html()
+ passthrough.assert_not_called()
+
+
[email protected]("path", ["/dashboard/static", "/dashboard/static/"])
+def test_static_directory_boundaries_are_not_forwarded(client, passthrough, path: str):
+ resp = client.get(path)
+
+ assert resp.status_code == 404
+ assert resp.text == "Not Found"
+ passthrough.assert_not_called()
+
+
+def test_unrelated_unknown_path_still_reaches_passthrough(client, passthrough):
+ resp = client.get("/unrelated-unknown-path")
+
+ assert resp.status_code == 418
+ passthrough.assert_awaited_once()
def test_dashboard_only_references_served_assets(client):