fix(gateway): strip Origin header for gateway proxy — CORS 403
Browse filesThe gateway's CORS middleware (api_server.py:557-558) returns 403 for
ANY non-empty Origin header when API_SERVER_CORS_ORIGINS is not
configured. The router was forwarding Origin: http://127.0.0.1:8642 on
all proxied requests (needed for the dashboard's own origin check), but
this caused the gateway to reject every /v1/* and /api/sessions request
with 403 Forbidden — even with a valid Bearer token.
Fix: strip the Origin header (set to empty string) when proxying to the
gateway (port 8642). The gateway treats empty Origin as a non-browser
client and allows it (api_server.py:886-887). The dashboard (port 9119)
still gets the local Origin rewrite it needs.
This fixes the Hermes Android app (and any other API client) getting
'invalid api key' / 403 when connecting through the Space.
- health-server.js +8 -1
|
@@ -406,7 +406,14 @@ function proxyRequest(
|
|
| 406 |
...req.headers,
|
| 407 |
...headerOverrides,
|
| 408 |
host: `${GATEWAY_HOST}:${targetPort}`,
|
| 409 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
"x-forwarded-host": req.headers.host || "",
|
| 411 |
"x-forwarded-proto": req.headers["x-forwarded-proto"] || "https",
|
| 412 |
};
|
|
|
|
| 406 |
...req.headers,
|
| 407 |
...headerOverrides,
|
| 408 |
host: `${GATEWAY_HOST}:${targetPort}`,
|
| 409 |
+
// The dashboard (port 9119) checks Origin against its own bind host and
|
| 410 |
+
// rejects mismatches, so we rewrite Origin to the local backend. But the
|
| 411 |
+
// gateway (port 8642) has a CORS middleware that returns 403 for ANY
|
| 412 |
+
// non-empty Origin when API_SERVER_CORS_ORIGINS is not configured. Since
|
| 413 |
+
// the router is a reverse proxy (not a browser making a CORS request),
|
| 414 |
+
// strip Origin for gateway calls so the gateway treats it as a non-browser
|
| 415 |
+
// client and allows it. headerOverrides can re-add it if needed.
|
| 416 |
+
origin: targetPort === GATEWAY_PORT ? "" : localOrigin,
|
| 417 |
"x-forwarded-host": req.headers.host || "",
|
| 418 |
"x-forwarded-proto": req.headers["x-forwarded-proto"] || "https",
|
| 419 |
};
|