Farhan Beg commited on
Commit
eecc3ba
Β·
1 Parent(s): 060f85e

fix(webui): only route /api/sessions to gateway for Bearer-auth requests

Browse files

The previous /api/sessions route (commit b0371e0) intercepted ALL
/api/sessions requests, including the WebUI's own session-list calls.
The WebUI (nesquena/hermes-webui) calls GET /api/sessions with cookie
auth to list sessions. My route sent those to the gateway (port 8642)
instead, which returned a different JSON format β†’ the WebUI's JS
didn't recognize the sessions β†’ login loop (POST /api/auth/login β†’ 200,
GET /session/{id} β†’ 200, GET /login?next=... β†’ 200, repeat).

Fix: only route /api/sessions to the gateway when the request carries a
Bearer token (Authorization: Bearer ...). The Android app and other API
clients send Bearer β†’ go to the gateway. The WebUI uses cookies (no
Bearer) β†’ falls through to the WebUI catch-all as before.

Files changed (1) hide show
  1. health-server.js +10 -6
health-server.js CHANGED
@@ -1108,12 +1108,16 @@ const server = http.createServer(async (req, res) => {
1108
 
1109
  // 5b. /api/sessions and /api/sessions/* β€” Hermes gateway session API.
1110
  // The Android app (rusty4444/hermes-android) and other OpenAI-compatible
1111
- // clients call these directly on the gateway (port 8642), not through
1112
- // /v1/. Without this route they hit the WebUI catch-all, which uses a
1113
- // different auth scheme β†’ 401 "invalid api key".
1114
- // Gate on Bearer token (same as /v1/*). The WebUI's own /api/* calls use
1115
- // cookie auth and don't hit /api/sessions, so there's no conflict.
1116
- if (path === "/api/sessions" || path.startsWith("/api/sessions/")) {
 
 
 
 
1117
  if (!isAuthorized(req)) {
1118
  res.writeHead(401, {
1119
  "content-type": "application/json",
 
1108
 
1109
  // 5b. /api/sessions and /api/sessions/* β€” Hermes gateway session API.
1110
  // The Android app (rusty4444/hermes-android) and other OpenAI-compatible
1111
+ // clients call these directly on the gateway (port 8642) with a Bearer
1112
+ // token. The WebUI (nesquena/hermes-webui) ALSO calls /api/sessions but
1113
+ // uses cookie auth (no Bearer). To avoid intercepting the WebUI's own
1114
+ // session calls (which caused a login loop), only route to the gateway
1115
+ // when the request carries a Bearer token. Requests without Bearer fall
1116
+ // through to the WebUI catch-all as before.
1117
+ if (
1118
+ (path === "/api/sessions" || path.startsWith("/api/sessions/")) &&
1119
+ getBearerToken(req)
1120
+ ) {
1121
  if (!isAuthorized(req)) {
1122
  res.writeHead(401, {
1123
  "content-type": "application/json",