Skip to content

feat(vault): Bitwarden folder as a login provider through the bw CLI (desktop app) - #34

Merged
zereight merged 2 commits into
mainfrom
feat/bitwarden-vault-provider
Nov 15, 2026
Merged

zereight merged 2 commits into
mainfrom
feat/bitwarden-vault-provider

Conversation

@zereight

Copy link
Copy Markdown
Owner

What changed

Adds Bitwarden as a second linked password manager next to 1Password, through the bw CLI on the person's own computer.

  • server/bitwarden.ts (new): BitwardenLogins implements VaultProvider, the bw runner and the folder snapshot.
  • Settings → Vault gets a Bitwarden section: Unlock (master password dialog), choose one folder, choose which bots may use it, Lock, Disconnect.
  • New routes, all under /api/logins/bitwarden: GET, DELETE, POST /unlock, POST /lock, PUT /folder, PATCH /bots.
  • fill_login fills Bitwarden logins (password plus TOTP). Bots can read the folder's secure notes and the custom fields of its logins as secrets.
  • When Bitwarden is locked, which happens after every restart, a bot that finds no login is told "Bitwarden is locked, unlock it in Settings → Vault". It is not sent off asking the person to sign in.
  • Strings in en, ko, ja, zh, zh-tw, pt-br. Other languages fall back to English.

How an unlock works:

  1. bw unlock --passwordfile /dev/stdin --raw (the master password is written to stdin)
  2. bw sync
  3. bw list folders
  4. bw list items --folderid <chosen>
  5. bw lock, which always runs, in finally

The session key lives for a few seconds and is dead once step 5 runs. The folder's items stay only in this process's memory until the person locks it or the app restarts.

Why

People who use Bitwarden instead of 1Password had no way to let bots sign in with their saved logins. A personal Bitwarden vault has no narrow, long-lived token like a 1Password service account, so this follows the design reviewed by DevilsAdvocate. It keeps the master password and session key out of reach of other processes run by the same user, and only ever loads one folder.

Security decisions:

  • The master password never goes in env or argv. A Node-based bw exposes its env to ps eww from any process of the same user, and DevilsAdvocate reproduced this. BW_SESSION and BW_PASSWORD inherited from the server are stripped. The session is put in the child's env only for the follow-up calls of a single unlock, and it is locked right after.
  • One folder only. Folder ids must be GUIDs (null and notnull are refused, since bw reads them as "every item without / with a folder"). They must also appear in bw list folders. Every returned item's folderId is checked again.
  • URI match rules are honoured. Regex (4) and Never (5) are skipped. Host (1), Starts with (2) and Exact (3) fill on their own host only. Base domain and the default fill on the site.
  • Secrets are allowlisted. Only text and hidden custom fields count. Booleans and linked fields are left out (a held "true" would be masked everywhere). The TOTP seed is only filled and never handed to a bot. Login notes, cards, identities and SSH keys are left out.
  • A newly chosen folder is given to no bots ([]) until the person picks some.
  • Desktop app only: desktopMutationToken set, not cloud, not hosted, not Windows. Elsewhere the routes answer 404 and /api/logins and /api/vault stay exactly as before, with no bitwarden key.
  • After 5 wrong master passwords, each try waits: 30 s, doubling up to 15 min. The unlock body is capped at 4 KB. bw stderr is classified and never echoed. Output is capped at 64 MB with a 60 s timeout. bw runs one call at a time.

How it was verified

  • pnpm typecheck: pass. pnpm lint (oxlint --deny-warnings): pass. The pre-push guards (file-size ratchet, vocabulary) pass.
  • server/bitwarden.test.ts, 15 tests:
    • folder filter and re-check
    • field allowlist, with the TOTP seed never a secret and a Steam key giving no TOTP
    • URI match rules
    • stderr classification
    • unlock, where the password is only on stdin, only the chosen folder is listed, and lock runs last even when listing fails
    • bots allowed and refused
    • forgetting items on lock and on a folder change
    • rate limit
    • off when unavailable
    • real child process (spawnBw with node): stdin is passed, and the inherited BW_SESSION/BW_PASSWORD are stripped
    • routes end to end: 404 outside the desktop app; unlock → folder → bots → list (read-only, delete gives 409) → lock → forget; no response body contains the master password, a site password, an API key, the session key or a note
  • Related suites: server/routes/, server/host/, server/bot-logins, login-fill, onepassword, vault-store, secret-vault, src/components/VaultSettings, src/lib, src/i18n: 497 files, 6524 tests passed.
  • Real bw 2026.10.0 on macOS, logged in and locked, wrong master password, through BitwardenLogins.unlock:
    • The answer is "The master password did not unlock Bitwarden." and nothing from stderr is passed through.
    • ps -axww -E -o args was sampled every 30 ms while bw ran (50 samples, argv and env). The password appeared 0 times.
    • bw status stays locked afterwards.
    • A real successful unlock was not run, because that needs the owner's master password, typed into Settings by them.

Before / After

Before (main ec40eca): there is no Bitwarden provider at all.

$ npx vitest run server/bitwarden.test.ts      # same test file on main
 ❯ server/bitwarden.test.ts:9:1
      9| import { BitwardenError, BitwardenLogins, bitwardenProblemOf, loginPla…
 Test Files  1 failed (1)      Tests  no tests
$ grep -n "LoginSource =" shared/logins.ts
11:export type LoginSource = "card" | "settings" | "1password";

After (this branch):

$ npx vitest run server/bitwarden.test.ts
 Test Files  1 passed (1)      Tests  15 passed (15)
real bw, wrong password: ps samples: 50, leaks (argv+env): 0 · bw status: locked

Limits

  • The app shares the person's bw data folder. Unlocking or locking in the app also locks a bw session they have open in a terminal. The unlock dialog says so. Setting BITWARDENCLI_APPDATA_DIR in the server's environment gives the app its own folder, at the cost of a second bw login.
  • It locks again on every restart. Automations that run at night cannot use Bitwarden logins until someone unlocks it.
  • First setup takes two unlocks: one to list folders and choose one, then one to load it.
  • There is no live sync. Changes made in Bitwarden show up at the next unlock.
  • JS strings cannot be wiped from the V8 heap, so the loaded values could appear in a crash dump or heap snapshot. The same is true of 1Password.
  • Not available on Windows (no /dev/stdin, and npm's bw.cmd needs a shell).

Checklist

  • pnpm typecheck and the related pnpm test suites pass locally
  • Server behavior changes come with tests
  • No dist-server/ edits
  • Platform-gated (no Windows); spawned without a shell
  • No secrets in logs, responses, events, or argv

tao.exe added 2 commits November 16, 2026 06:04
… desktop app only

Unlock with the master password (on stdin), read one chosen folder, lock bw again at once.
Items stay in memory until lock or restart. Folder ids checked as GUIDs, URI match rules
honoured, only text/hidden custom fields as secrets, 2FA keys only filled.
@zereight
zereight merged commit daa768e into main Nov 15, 2026
1 of 2 checks passed
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.

1 participant