Repository navigation
Stop exposing manager API key in the browser bundle - #731
Conversation
VITE_* env vars are public by design — Vite inlines them into the browser bundle at build time, so any static key read via import.meta.env is readable from DevTools. api.ts read VITE_BACKEND_API_KEY and sent it as an `Authorization: Bearer` header on every management request, exposing the manager API key whenever the bundle was built with the var set. Management endpoints are already authenticated by the OSC platform session: the production Docker build never sets VITE_BACKEND_API_KEY, and requests are authenticated same-origin by the short-lived `*.sat` cookie that the existing /reauth flow keeps fresh. fetch defaults to credentials: "same-origin", so that cookie rides along without any extra client config. - Remove the API_KEY constant and every Authorization: Bearer header from api.ts; requests now rely on the same-origin session cookie. - Drop the VITE_BACKEND_API_KEY dev instructions from the README and add a security note explaining why the frontend must not hold the key. Closes #625 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Code Review — Verdict: LGTMAutomated self-review by today's daily-backlog-pr run (code-reviewer agent, a separate invocation from the implementer). Recorded as a marker comment because GitHub blocks state-bearing self-approval on a self-authored PR. Summary: Clean, correct fix for the High-severity secret-exposure issue (#625). The manager API key is fully removed from the client — not merely relocated — and auth now relies on the OSC platform's same-origin session cookie, the mechanism the production deployment already used. BlockingNone. Verified: zero reads of Warnings (non-blocking)
Suggestions
|
Summary
src/api/api.tsreadVITE_BACKEND_API_KEYviaimport.meta.envand sent it as anAuthorization: Bearerheader on every management request. AllVITE_*vars are public by design (Vite inlines them into the browser bundle at build time), so any bundle built with the var set leaked the manager API key to anyone with DevTools (Security: VITE_BACKEND_API_KEY exposes API key in browser bundle #625, High severity).API_KEYconstant and allAuthorization: Bearerheaders. Requests now authenticate via the OSC platform session: the browser talks to the manager same-origin and the short-lived*.satsession cookie (kept fresh by the existing/reauthflow) is sent automatically.fetchdefaults tocredentials: "same-origin", so no extra client config is needed.VITE_BACKEND_API_KEY(onlyMANAGER_URL/AUTHare baked in), so deployed bundles already send noAuthorizationheader and rely on the session cookie today — this change only removes the dead-but-dangerous code path.VITE_BACKEND_API_KEY=<service-access-token> npm run devinstructions and added a security note explaining the frontend must never hold the key. (.env.local.samplenever referenced the var, so no change was needed there.)Test plan
npm test— 346 tests across 42 files passnpm run typecheck— cleannpm run lint— clean (max-warnings 0)VITE_BACKEND_API_KEY/API_KEY/Authorizationreferences remain insrc/Authorizationheader (none did)Closes #625
🤖 Generated with Claude Code