Stop sending target cookies from the HTTP service #7

Merged
raucao merged 1 commits from bugfix/openrouter into master 2026-11-16 08:25:55 +00:00
Owner

Firefox treats an extension page's fetch to a host-permission origin as same-origin, so it attached the target origin's cookies to every request from the shared HTTP service. OpenRouter's /analytics/query runs Clerk auth whenever a session cookie is present and read the management key in the Authorization header as a session JWT, answering 403 ("Invalid JWT form"). Cookie-less requests (e.g. curl) use OpenRouter's API-key auth path and returned 200, which is why "Load keys" worked while the dashboard spend total failed.

The fix defaults the shared fetch to credentials: "omit" so extension requests never carry the target origin's cookies and authenticate purely via headers. It stays overridable per call, and every current consumer (site-icons, bitcoin, notifications, openrouter) authenticates with headers or hits public APIs.

classifyError() now also surfaces OpenRouter's own error.message for failed requests, falling back to the existing status summaries, so future auth or permission failures stay diagnosable instead of showing a generic "Management key required".

Adds unit tests for the credentials default and override, and for the surfaced API message.

Firefox treats an extension page's `fetch` to a host-permission origin as same-origin, so it attached the target origin's cookies to every request from the shared HTTP service. OpenRouter's `/analytics/query` runs Clerk auth whenever a session cookie is present and read the management key in the `Authorization` header as a session JWT, answering `403` ("Invalid JWT form"). Cookie-less requests (e.g. `curl`) use OpenRouter's API-key auth path and returned `200`, which is why "Load keys" worked while the dashboard spend total failed. The fix defaults the shared fetch to `credentials: "omit"` so extension requests never carry the target origin's cookies and authenticate purely via headers. It stays overridable per call, and every current consumer (site-icons, bitcoin, notifications, openrouter) authenticates with headers or hits public APIs. `classifyError()` now also surfaces OpenRouter's own `error.message` for failed requests, falling back to the existing status summaries, so future auth or permission failures stay diagnosable instead of showing a generic "Management key required". Adds unit tests for the credentials default and override, and for the surfaced API message.
raucao added 1 commit 2026-11-16 08:23:09 +00:00
Extension pages with host permissions are treated as same-origin, so the
target origin's cookies rode along on every request. OpenRouter's
Clerk-protected analytics endpoint then tried to read the management key in
the Authorization header as a session JWT and answered 403, breaking the
spend total on the dashboard.

Default the shared fetch to credentials "omit" (still overridable per call),
and surface OpenRouter's own error message for failed requests instead of a
generic status summary.
raucao added the bug label 2026-11-16 08:25:33 +00:00
raucao merged commit 865402938a into master 2026-11-16 08:25:55 +00:00
raucao deleted branch bugfix/openrouter 2026-11-16 08:25:55 +00:00
Sign in to join this conversation.