[browser] Firefox: one extension source for Firefox, Edge and Chrome; frames, public suffixes, the caller check, 2FA codes and saving logins; v0.20.0
- custos-browser: fill_allowed (a frame gets a login only when its page would too), public suffixes match exactly only (psl), ports digits only, caller (which extension started the host); spoof tests. - custos-native: answers not_allowed to anything but the Custos extension, browser_totp and browser_save, the frame's and the page's origins, a random session per connection (its match code on Custos's cards). - extension/: manifest.firefox.json (gecko id custos@marek-novak.cz) and manifest.chromium.json, one set of scripts; the popup shows 2FA codes, the save offer and the connection's code; tools/extension.mjs builds each browser and reproducible zips; tools/extension-test.mjs runs the background against a fake browser.
This commit is contained in:
+67
-36
@@ -1,12 +1,13 @@
|
||||
# Custos in the browser
|
||||
|
||||
Version 1 of the browser extension: Chromium (Edge and Chrome) on Windows, logins only. Passkeys come later.
|
||||
Version 2 of the browser extension (core 0.20.0): Firefox, Edge and Chrome on Windows, from one source; logins
|
||||
and their 2FA codes, and saving a new login. Passkeys come later.
|
||||
The extension, its native host and the rule that decides which login belongs on which page are all in this
|
||||
public repository, so anyone can read what the browser side does. The desktop app (the private `Custos`
|
||||
repo) holds the vault and answers the host; its side is `docs/13_browser.md` there.
|
||||
|
||||
```
|
||||
page ─(content script)─► service worker ─(native messaging)─► custos-native.exe ─(\\.\pipe\custos-domi)─► custos.exe
|
||||
page ─(content script)─► background ─(native messaging)─► custos-native.exe ─(\\.\pipe\custos-domi)─► custos.exe
|
||||
extension/content.js extension/background.js crates/custos-native the desktop app
|
||||
```
|
||||
|
||||
@@ -14,11 +15,12 @@ page ─(content script)─► service worker ─(native messaging)─► custos
|
||||
|
||||
| Piece | What it does | What it never does |
|
||||
|:--|:--|:--|
|
||||
| `extension/content.js` | Finds login fields (password, username next to one, one-time code); on focus shows a small Custos button in a **closed** shadow root; on click asks for the logins of *its own frame*, and fills the one the person picks. | Fill without a click; read anything from Custos before the list is opened; trust what the page says about its own address. |
|
||||
| `extension/popup.*` | The toolbar popup: the logins for the active tab; a click asks the top frame's content script to fill. | Receive a password: the content script asks for the secrets itself. |
|
||||
| `extension/background.js` | Owns the one connection to the native host; turns each request into `browser_status`, `browser_match` or `browser_fill`, with the origin taken from **`sender.url`** (the frame's real URL, as the browser reports it). | Accept messages from pages or other extensions (`sender.id` must be its own). |
|
||||
| `crates/custos-native` | The native messaging host. Reads frames from stdin, **rebuilds** each request from its known fields (op, origin ≤ 2 KiB, id ≤ 128 bytes, seq), forwards it to the Custos pipe and returns the answer. | Forward any other Domi op (`get`, `list`, `sign`, …); talk to a pipe served by anything but `custos.exe`; keep a secret after the answer is written (frames and parsed answers are zeroized). |
|
||||
| `crates/custos-browser` | `Origin::parse`, `login_matches`, `best_match` (which login fits which page) and the native messaging framing. The desktop uses the same crate, so both sides apply one rule. | Fuzzy matching of any kind. |
|
||||
| `extension/content.js` | Finds login fields (password, username next to one, one-time code); on focus shows a small Custos button in a **closed** shadow root; on a (trusted) click asks for the logins of *its own frame*, and fills the one the person picks: username and password, or only the 2FA code on a page that asks only for that. When a form is sent with a password the person typed (not one Custos filled), offers to save it. | Fill without a click; read anything from Custos before the list is opened; put a secret anywhere but its field; trust what the page says about its own address. |
|
||||
| `extension/popup.*` | The toolbar popup: the logins for the active tab, a 2FA code on request, a login offered for saving, and this connection's match code. A click asks the top frame's content script to fill. | Receive a password: the content script asks for the secrets itself. |
|
||||
| `extension/background.js` | Owns the one connection to the native host; turns each request into a `browser_*` op, with the frame's origin from **`sender.url`** and its page's from **`sender.tab.url`** (as the browser reports them). Holds a login offered for saving in memory, for its tab, at most 3 minutes. | Accept messages from pages or other extensions (`sender.id` must be its own); ask for a frame whose real origin is not its URL's (`sender.origin`, e.g. a sandboxed frame); write anything to `storage`. |
|
||||
| `crates/custos-native` | The native messaging host. Checks who started it (`custos_browser::caller`); reads frames from stdin, **rebuilds** each request from its known fields, adds its connection's `session`, forwards it to the Custos pipe and returns the answer. | Answer an extension that is not Custos's (`not_allowed`, nothing reaches Custos); forward any other Domi op (`get`, `list`, `sign`, …); talk to a pipe served by anything but `custos.exe`; keep a secret after the answer is written (frames and parsed messages are zeroized). |
|
||||
| `crates/custos-browser` | `Origin::parse`, `login_matches`, `best_match`, `fill_allowed` (which login fits which frame of which page), `caller`, and the native messaging framing. The desktop uses the same crate, so both sides apply one rule. | Fuzzy matching of any kind. |
|
||||
| `tools/extension.mjs` | Builds `target/extension/firefox/` and `…/chromium/` from the one source with each browser's manifest (`extension/manifest.<browser>.json`) and the workspace version; `--zip` writes reproducible packages for AMO and the stores. | Differ per browser: the scripts are the same files. |
|
||||
|
||||
## Which login goes where (`custos-browser`)
|
||||
|
||||
@@ -31,69 +33,98 @@ fields (an item may have several) match a page when:
|
||||
3. the ports are equal (the stored URL's port, or the scheme's default when it names none);
|
||||
4. the page's host is the login's host (**exact**; `www.` counts as the host) or a subdomain of it
|
||||
(**subdomain**: `accounts.github.com` for `github.com`). A login for a subdomain never goes to its parent
|
||||
or to a sibling. A login for an IP address or a bare name (`cz`) matches only that exact host.
|
||||
or to a sibling. A login for an IP address, a bare name (`cz`) or a **public suffix** (`co.uk`, `github.io`,
|
||||
`herokuapp.com`: Mozilla's Public Suffix List, the `psl` crate) matches only that exact host, because the
|
||||
subdomains of a public suffix belong to different people;
|
||||
5. **in a frame** (`fill_allowed`): the frame matches, and when the frame is not the top page, the top page
|
||||
matches too. `evil.net` framing `github.com/login` gets nothing, and neither does an ad frame on
|
||||
`github.com`.
|
||||
|
||||
URLs with userinfo (`https://bank.cz@evil.net`) are refused outright. Look-alikes (`github.com.evil.net`,
|
||||
URLs with userinfo (`https://bank.cz@evil.net`), a port that is not only digits (`:+443`) or a host that is not
|
||||
ASCII (the browser reports punycode, and that is what is compared) are refused outright. Look-alikes (`github.com.evil.net`,
|
||||
`githuh.com`, punycode twins) never match, because nothing is compared but labels. Exact matches are offered
|
||||
before subdomain matches, then by title; at most 50 logins per page.
|
||||
|
||||
## The messages
|
||||
|
||||
Native messaging frames: a 4-byte little-endian length, then UTF-8 JSON. The host accepts at most 64 KiB per
|
||||
message (the desktop pipe's limit). Every request may carry `seq` (a number); the answer carries it back.
|
||||
Native messaging frames: a 4-byte little-endian length, then UTF-8 JSON (the same in Firefox and Chromium). The
|
||||
host accepts at most 64 KiB per message (the desktop pipe's limit). Every request may carry `seq` (a number); the
|
||||
answer carries it back. The host adds `app`, `browser` (`firefox` from its arguments; `edge`, `chrome` or
|
||||
`chromium` as the extension says, a label) and `session` (64 hex digits, random per connection) to each.
|
||||
|
||||
| Extension → host | Host → Custos | Answer |
|
||||
|:--|:--|:--|
|
||||
| `{"op":"browser_status"}` | `{"op":"browser_status","app":"Custos for your browser"}` | `{"ok":true}` |
|
||||
| `{"op":"browser_match","origin":"https://github.com"}` | + `origin` | `{"ok":true,"logins":[{"id","title","username"}]}`: never a password |
|
||||
| `{"op":"browser_fill","id":"…","origin":"…"}` | + `origin`, `id` | `{"ok":true,"username","password","totp"}` only if that login matches `origin`, else `"error":"no_match"` |
|
||||
| Extension → host | Answer |
|
||||
|:--|:--|
|
||||
| `{"op":"browser_status"}` | `{"ok":true,"code":"123456"}`: the session's match code |
|
||||
| `{"op":"browser_match","origin","top"}` | `{"ok":true,"logins":[{"id","title","username","totp"}]}` (`totp`: it has a 2FA code); never a secret |
|
||||
| `{"op":"browser_fill","id","origin","top"}` | `{"ok":true,"username","password","totp"}` only if that login may go into that frame of that page, else `no_match` |
|
||||
| `{"op":"browser_totp","id","origin","top"}` | `{"ok":true,"totp","remaining"}` (seconds left) under the same rule; `no_totp` without one |
|
||||
| `{"op":"browser_save","origin","top","username","password"[,"title"]}` | after Custos's card: `{"ok":true,"saved":"new"/"updated"/"unchanged"}`, or `refused` |
|
||||
|
||||
Errors the extension turns into a sentence: `not_connected` (no host registered), `not_running`,
|
||||
`not_custos` (the pipe's server is not `custos.exe`: nothing was sent), `locked`, `denied`, `not_found`,
|
||||
`no_match`, `no_answer`, `bad_request`.
|
||||
Limits: `origin`, `top` ≤ 2 KiB, `id` ≤ 128 bytes, `username` ≤ 1 KiB, `password` 1 byte to 4 KiB, `title`
|
||||
≤ 200 bytes. Errors the extension turns into a sentence: `not_connected` (no host registered), `not_allowed`
|
||||
(not the Custos extension), `not_running`, `not_custos` (the pipe's server is not `custos.exe`: nothing was sent),
|
||||
`locked`, `denied`, `refused`, `not_found`, `no_match`, `no_totp`, `no_answer`, `bad_request`.
|
||||
|
||||
## What Custos checks (the desktop's side, summarised)
|
||||
|
||||
- The host is a Domi client like any other: Custos identifies it by its executable and asks the person once
|
||||
whether it may use **`web-logins/`**. That grant is the browser's only; no `domi://` ref may use the
|
||||
`web-logins` namespace and the browser ops reach nothing else.
|
||||
- Custos parses the origin again with `custos-browser` and checks the login against it on **every**
|
||||
`browser_fill`, whatever the extension asked for before.
|
||||
- Custos parses both origins again with `custos-browser` and checks the login with `fill_allowed` on **every**
|
||||
`browser_fill` and `browser_totp`, whatever the extension asked for before.
|
||||
- The grant card shows the session's match code, the one the popup shows. Every fill, code and save goes in the
|
||||
vault's audit with that code.
|
||||
- `browser_save` always shows a card (*Save* / *Don't save*): a new *Web login* for the origin, or, when a login
|
||||
of that site has the same username, its new password. An identical login is `unchanged`, without a card.
|
||||
- Only items of type *Web login* are offered. A locked Custos waits for the unlock (up to a minute), then
|
||||
answers `locked`.
|
||||
|
||||
## Registration and the extension id
|
||||
## Registration and the extension ids
|
||||
|
||||
The extension's `manifest.json` carries a public `key`, which fixes its id to
|
||||
**`jchkapmceepdnlhagfppeckggaecdcmn`** however it is loaded (unpacked or packed). The desktop's *Connect*
|
||||
writes the host manifest with `"allowed_origins": ["chrome-extension://jchkapmceepdnlhagfppeckggaecdcmn/"]`
|
||||
and registers it under `HKCU\Software\Microsoft\Edge\NativeMessagingHosts\cz.marek_novak.custos` and
|
||||
`HKCU\Software\Google\Chrome\NativeMessagingHosts\cz.marek_novak.custos`, so only this extension can start
|
||||
the host. The private key that matches the public key is not in this repository; it is only needed to pack a
|
||||
`.crx` with the same id.
|
||||
| Browser | Extension id | Host manifest | Registry (HKCU, per user) |
|
||||
|:--|:--|:--|:--|
|
||||
| Firefox | `custos@marek-novak.cz` (`browser_specific_settings.gecko.id`) | `"allowed_extensions": ["custos@marek-novak.cz"]` | `Software\Mozilla\NativeMessagingHosts\cz.marek_novak.custos` |
|
||||
| Edge | `jchkapmceepdnlhagfppeckggaecdcmn` (the `key` in `manifest.chromium.json`) | `"allowed_origins": ["chrome-extension://jchkapmceepdnlhagfppeckggaecdcmn/"]` | `Software\Microsoft\Edge\NativeMessagingHosts\cz.marek_novak.custos` |
|
||||
| Chrome | the same | the same | `Software\Google\Chrome\NativeMessagingHosts\cz.marek_novak.custos` |
|
||||
|
||||
The desktop writes both host manifests and registers them. The Chromium `key` fixes the id however the extension
|
||||
is loaded; the private key that matches it is not in this repository (it is held in Custos) and is needed only to
|
||||
pack a `.crx`, or for the first upload to the Chrome Web Store, to keep the id. Release Firefox installs only
|
||||
add-ons signed by Mozilla: the Firefox zip is signed through AMO as an *unlisted* (self-distributed) add-on.
|
||||
|
||||
## Threat model, briefly
|
||||
|
||||
- A malicious **page** cannot ask for a login: content scripts run in an isolated world, the button and list
|
||||
are in a closed shadow root, the origin comes from the browser, and filling needs a click in Custos's own UI.
|
||||
A page *can* read what was filled into its own fields: that is what filling is.
|
||||
- A malicious **frame** on a good site is a different origin: it gets only its own origin's logins.
|
||||
- Another **extension** cannot message this one (`sender.id`), and cannot start the host (`allowed_origins`).
|
||||
- A malicious **frame** on a good site is a different origin: it gets only its own origin's logins, and those
|
||||
only if the page around it matches them too. A good site framed by a malicious page gets nothing.
|
||||
- Another **extension** cannot message this one (`sender.id`), cannot start the host (`allowed_origins`,
|
||||
`allowed_extensions`), and if a stray manifest let it, the host answers it only `not_allowed` (`caller`).
|
||||
- A page can make the extension *offer* to save a login for **its own** origin, with values of its choosing; it
|
||||
is saved only on Custos's card, which names the site.
|
||||
- A program that **impersonates Custos** by creating the pipe first gets nothing: the host checks the pipe
|
||||
server's image path ends in `\custos.exe` before writing the request. (A process of the same user that can
|
||||
replace `custos.exe` is out of scope, as everywhere in Custos: docs/THREAT_MODEL.md.)
|
||||
- The extension holds no secret at rest and no state beyond the open native port.
|
||||
- The extension holds no secret at rest. Its only state is the open native port and, for a login offered for
|
||||
saving, that login in the background's memory for at most 3 minutes (JavaScript strings cannot be wiped;
|
||||
they are dropped).
|
||||
|
||||
## Not yet
|
||||
|
||||
Passkeys (WebAuthn through the extension), Firefox, saving new logins from the browser, filling cards.
|
||||
Passkeys (WebAuthn through the extension), filling cards, other operating systems.
|
||||
|
||||
## Tests
|
||||
|
||||
```
|
||||
cargo test -p custos-browser -p custos-native
|
||||
node tools/extension-test.mjs
|
||||
```
|
||||
|
||||
`custos-browser` covers origin parsing, look-alikes, ports and schemes, bare names and IPs, best-of-several and
|
||||
the frames; `custos-native` that only the three ops pass, rebuilt from known fields. The desktop repo has the
|
||||
pipe tests and an end-to-end run in Edge.
|
||||
`custos-browser` covers origin parsing, look-alikes (punycode twins, extra labels, userinfo, encoded dots,
|
||||
backslashes, odd ports), public suffixes, frames and their pages, ports and schemes, bare names and IPs,
|
||||
best-of-several, the callers and the frames. `custos-native` covers that only the five ops pass, rebuilt from
|
||||
known fields, and that another extension gets `not_allowed` without reaching Custos. `tools/extension-test.mjs`
|
||||
runs the background script against a fake browser: origins from the browser and never from the message, frames,
|
||||
sandboxed and blank frames, other extensions, a locked Custos, and a login offered for saving that never comes back
|
||||
out. The desktop repo has the pipe tests and the end-to-end runs in each browser.
|
||||
|
||||
Reference in New Issue
Block a user