Skip to content

Commit e94b60e

Browse files
committed
fix(server): /admin routes must sit before the global auth gate
The global proxyApiKey gate doesn't know the ?key= flow — it rejected /admin/state before the route's own auth ran. /admin (shell) and /admin/state (own auth: header or ?key=) now sit before the gate.
1 parent f4a53c0 commit e94b60e

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

‎src/server/server.ts‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ export function createFetchHandler(opts: ServerOptions): (req: Request) => Promi
9292
});
9393
}
9494

95+
// Admin dashboard: the HTML shell is unauthenticated (no data in it);
96+
// its data endpoint /admin/state enforces the proxy API key itself
97+
// (header OR ?key= — browsers can't set custom headers on fetch without
98+
// CORS setup). Must sit BEFORE the global auth gate, which doesn't know
99+
// about the ?key= flow.
100+
if (method === "GET" && (path === "/admin" || path === "/admin/" || path === "/admin/state")) {
101+
if (path === "/admin/state") {
102+
return handleAdminState(req, { proxyApiKey: config.auth.proxyApiKey });
103+
}
104+
return new Response(ADMIN_DASHBOARD_HTML, {
105+
status: 200,
106+
headers: { "content-type": "text/html; charset=utf-8", "cache-control": "no-cache" },
107+
});
108+
}
109+
95110
if (config.auth.proxyApiKey) {
96111
const authHeader = req.headers.get("authorization") ?? req.headers.get("x-api-key");
97112
if (!authHeader || !checkProxyKey(authHeader, config.auth.proxyApiKey)) {
@@ -115,10 +130,6 @@ export function createFetchHandler(opts: ServerOptions): (req: Request) => Promi
115130
return handleQuota(config, opts.fetchImpl, undefined, opts.accountPool);
116131
}
117132

118-
if (path === "/admin/state" && method === "GET") {
119-
return handleAdminState(req, { proxyApiKey: config.auth.proxyApiKey });
120-
}
121-
122133
if (path === "/admin" && method === "GET") {
123134
// HTML dashboard. Read-only; the fetch inside passes ?key= as x-api-key
124135
// when the browser cannot set headers. Binds loopback by default.

0 commit comments

Comments
 (0)