Browser extension API key security mostly comes down to scope. A key an extension holds is a credential kept in a file, presented on every request, and usually far more powerful than the extension needs. Mosaic's companion, the extension inside every profile, held exactly that kind of key. We replaced it with a token issued per launch, kept in memory, that reaches one profile and nothing else.

How it was reported

The report came with a screenshot of the API page. Among the keys a person had made sat a row called In-browser companion, msc_ff27…67bb, with a Revoke button beside it. The request was plain: stop using a normal API key for the extension, because the logic around it is fragile.

The companion inside a profile's browser, showing that profile's two-factor codes
Every call the popup makes is about its own profile

Three faults that compound

companionSecret() called createApiKey('In-browser companion'), kept the plain text in a file under Mosaic's data folder, and handed it to the extension at every launch.

It appeared in the key list. Revoking a key you do not recognise is the sensible thing to do. Here it broke the popup until the next launch made the key again. The honest label for that Revoke button was "put this back in a moment", and a control whose only effect is to break something until it silently repairs itself is not a control.

It was a full-power credential. That key could create profiles, delete them, read the whole library and drive every other profile on the machine. We read the popup's own source to see what it uses: every request is a GET, PATCH or POST on /profiles/<its own id> or a route under it. The widest authority in the product had gone to its narrowest client.

It was a cached credential, and those go stale. The file outlives the key through a revoke, a restored backup or a moved data folder. Keeping the two in step needed a whole mechanism, which existed only to cover the first mistake.

Everything the window does, from a script on your own computerIn Mosaic: REST API. Everything the window does, from your own scripts. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.

How it works: REST API

Browser extension API key security: what replaced it

src/main/api/companion-session.ts makes a capability for the browser the launcher has just started. It is per launch, per profile, held in memory and never written to disk. It is not an API key. The server checks it before it checks API keys, so the two kinds of caller cannot be confused, and it never appears in the key list because it was never put there.

Why a token at all, rather than trusting where the request comes from? The local REST API listens on 127.0.0.1, so every program on the computer can open a socket to it. The extension's Origin header proves which extension sent a request. It proves nothing about everything else running as you. A secret the caller has to hold is the one thing that separates "the companion we built into this profile" from any other local process, and this one is as small as that job allows.

What the token can reach, measured

One profile started, and the token read out of the extension the launcher had just written:

GET    /profiles/<own>           200
PATCH  /profiles/<own>           200
GET    /profiles/<own>/cookies   200
GET    /profiles/<other>         403
GET    /profiles  (the library)  403
GET    /overview                 403
DELETE /profiles/<other>         403
unrevoked keys in the list       [ 'Arche' ]   (the companion is not one)
after the profile stops          401           (the session is gone)

The middle four are 403, not 401, on purpose. The companion is authenticated; it is being told the request is not its business. The popup still does everything it did before: notes, the cookie jar, saved logins and codes, the audit and the leak test, all for its own profile.

Old installs shed the key themselves

retireCompanionKey runs once at startup. It deletes the file nothing reads any more and revokes any unrevoked key named "In-browser companion". After the first run it finds neither and says nothing. On our machine, the first launch after the change logged:

[mosaic] Retired the companion's old API key — the popup now uses a
per-launch session instead (file removed: true, keys revoked: 1).

A full-power credential nobody uses is worse than one somebody does.

The check, and the trap it fell into

check:companion runs in every build. It no longer tests a cache, because there is none. It tests three things: a relaunch makes a new token and the old one stops working, two profiles never share a token, and a companion for one profile cannot reach another, the library, /overview or a bulk route. We proved each negative by putting the fault back and watching those exact lines fail.

One last assertion says the module never writes a secret or makes a key. Its first version failed against a module that does neither, because the module's header explains what it replaced and the pattern matched the prose. Comments are stripped before it searches now.

For an extension you write yourself, the rule that transfers is to start from the calls it makes and grant exactly those, for as long as the session that needs them lasts. The same popup carries each profile's saved logins and 2FA codes, read through this token. The API keys people do create are covered in the local API guide.