feat(webui): bypass tokens for trusted proxy auth

This commit is contained in:
concertypin authored and Xubin Ren committed 2026-08-04 21:53:16 +08:00
1 parent 5cd14a42df
commit 465a918cf8
9 files changed
+134 -62

No files matched your search

+27 -6
View File
@@ -266,6 +266,8 @@ class GatewayHTTPHandler:
# -- Token management ---------------------------------------------------
def check_api_token(self, request: WsRequest) -> bool:
if getattr(request, "_nanobot_trusted_proxy_authenticated", False):
return True
return self.tokens.check_api_token(request)
# -- Main dispatch ------------------------------------------------------
@@ -275,6 +277,11 @@ class GatewayHTTPHandler:
got, _ = _parse_request_path(request.path)
started = time.perf_counter()
response: Any | None = None
setattr(
request,
"_nanobot_trusted_proxy_authenticated",
_is_trusted_proxy_authenticated_request(connection, request.headers, self.config),
)
try:
response = await self._dispatch_resolved(connection, request, got)
@@ -380,13 +387,27 @@ class GatewayHTTPHandler:
request.headers,
self.config,
)
if secret:
if not _issue_route_secret_matches(request.headers, secret):
return _http_error(401, "Unauthorized")
elif not (is_local_browser or is_proxy_authenticated):
return _http_error(403, "bootstrap is localhost-only")
if not is_proxy_authenticated:
if secret:
if not _issue_route_secret_matches(request.headers, secret):
return _http_error(401, "Unauthorized")
elif not is_local_browser:
return _http_error(403, "bootstrap is localhost-only")
api_token_allowed = bool(secret) or is_local_browser or is_proxy_authenticated
if is_proxy_authenticated:
payload = {
"ws_path": _normalize_config_path(self.config.path),
"ws_url": self._bootstrap_ws_url(request),
"limits": self.ingress.bootstrap_limits(
max_frame_bytes=self.config.max_message_bytes,
),
"model_name": _resolve_bootstrap_model_name(self.runtime_model_name),
"runtime_surface": self._runtime_surface,
"runtime_capabilities": self._capabilities,
}
return _http_json_response(payload)
api_token_allowed = bool(secret) or is_local_browser
if not self.tokens.can_issue(include_api_token=api_token_allowed):
return _http_response(
json.dumps({"error": "too many outstanding tokens"}).encode("utf-8"),