Files
CustosPublic/docs/BROWSER.md

7.0 KiB

Custos in the browser

Version 1 of the browser extension: Chromium (Edge and Chrome) on Windows, logins only. 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
         extension/content.js   extension/background.js        crates/custos-native        the desktop app

The pieces

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.

Which login goes where (custos-browser)

A page's origin is scheme://host[:port], host lowercased, trailing dot removed. A login's stored url fields (an item may have several) match a page when:

  1. the page is fillable: https, or plain http only on this machine (localhost, *.localhost, 127.0.0.1, [::1]). Plain http on the internet is never filled, even for a login saved with http://;
  2. the schemes are equal (a stored URL without a scheme means https);
  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.

URLs with userinfo (https://bank.cz@evil.net) 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.

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"

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.

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.
  • 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

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.

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 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.

Not yet

Passkeys (WebAuthn through the extension), Firefox, saving new logins from the browser, filling cards.

Tests

cargo test -p custos-browser -p custos-native

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.