Skip to content

fix(desktop): inject Authorization header into match API requests via session.webRequest#3338

Open
ruanjf wants to merge 4 commits into
multica-ai:mainfrom
ruanjf:fix/desktop-auth-header-github
Open

fix(desktop): inject Authorization header into match API requests via session.webRequest#3338
ruanjf wants to merge 4 commits into
multica-ai:mainfrom
ruanjf:fix/desktop-auth-header-github

Conversation

@ruanjf
Copy link
Copy Markdown

@ruanjf ruanjf commented May 27, 2026

What does this PR do?

tags, iframes, and other non-fetch browser requests bypass the API
client and carry no Authorization header. The server's static file redirect
endpoint (GetStaticFileRedirect) requires either the Authorization header or
the multica_auth cookie — neither of which Electron sets automatically —
so authenticated images returned 401 and failed to display.

Fix: register a combined onBeforeSendHeaders handler on the renderer session
that injects Authorization: Bearer <token> for every request whose URL
starts with the configured API base URL. The token is kept in sync in the
main process via two new IPC channels (auth:set-token / auth:clear-token)
called by the renderer on login and logout respectively.

Related Issue

Closes #

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Refactor / code improvement (no behavior change)
  • Documentation update
  • Tests (adding or improving test coverage)
  • CI / infrastructure

Changes Made

How to Test

Checklist

  • I have included a thinking path that traces from project context to this change
  • I have run tests locally and they pass
  • I have added or updated tests where applicable
  • If this change affects the UI, I have included before/after screenshots
  • I have updated relevant documentation to reflect my changes
  • If I added a new runtime / coding tool / UI tab, I synced the change to landing copy (apps/web/features/landing/i18n/) and relevant docs (apps/docs/content/docs/)
  • If this PR touches Chinese product copy, I checked it against apps/docs/content/docs/developers/conventions.zh.mdx (terminology, mixed-rule for task / issue / skill)
  • I have considered and documented any risks above
  • I will address all reviewer comments before requesting merge

AI Disclosure

AI tool used:

Prompt / approach:

Screenshots (optional)

ruanjiefeng and others added 2 commits May 27, 2026 11:05
…ession.webRequest

<img> tags, iframes, and other non-fetch browser requests bypass the API
client and carry no Authorization header. The server's static file redirect
endpoint (GetStaticFileRedirect) requires either the Authorization header or
the multica_auth cookie — neither of which Electron sets automatically —
so authenticated images returned 401 and failed to display.

Fix: register a combined onBeforeSendHeaders handler on the renderer session
that injects `Authorization: Bearer <token>` for every request whose URL
starts with the configured API base URL. The token is kept in sync in the
main process via two new IPC channels (auth:set-token / auth:clear-token)
called by the renderer on login and logout respectively.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
…bRequest

Extract applyAuthRequestHeaders into a standalone module and cover it with
12 unit tests: Authorization injection for API requests, no-op when token or
base URL is absent, no override of an existing header, no mutation of the
input object, and Origin stripping for WebSocket upgrades.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 27, 2026

@ruanjiefeng is attempting to deploy a commit to the IndexLabs Team on Vercel.

A member of the Team first needs to authorize it.

@ruanjf ruanjf changed the title Fix/desktop auth header GitHub fix(desktop): inject Authorization header into all API requests via session.webRequest May 27, 2026
@ruanjf ruanjf changed the title fix(desktop): inject Authorization header into all API requests via session.webRequest fix(desktop): inject Authorization header into match API requests via session.webRequest May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants