Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(vault): Bitwarden Secrets Manager login fills only for the username its note still names; refresh after a reconnect reads the new connection
AdityaUmalefa5048ba57b9
diff --git a/server/host/bitwarden-secrets.test.ts b/server/host/bitwarden-secrets.test.tsindex 29f7558a9b..528207ea4a 100644--- a/server/host/bitwarden-secrets.test.ts+++ b/server/host/bitwarden-secrets.test.ts@@ -252,6 +252,36 @@ describe("Bitwarden Secrets Manager in the Vault", () => {expect((await candidate!.secrets()).password, "a new password on the same site").toBe("fake-rotated-Passw0rd");});+ it("gives a login's password only while its note still names the same username", async () => {+ const { vault, fake } = setup();+ await vault.refresh();+ const [candidate] = linkedCandidates(vault, "github.com", "pepper");+ fake.secrets[0]!.note = "url: https://github.com/login\nusername: replacement-bot";+ fake.secrets[0]!.value = "fake-replacement-Passw0rd";+ await expect(candidate!.secrets()).rejects.toThrow("no longer in");+ });++ it("reads the new connection on a refresh asked for after a reconnect, not the old one still being read", async () => {+ const old = fakeBws({ secrets: SECRETS });+ const next = fakeBws({ secrets: [{ key: "NEXT_KEY", value: "fake-next" }], serverUrl: "https://bw.example.test" });+ const fetch: SecretsFetch = (url, init) => (url.startsWith("https://bw.example.test") ? next.fetch(url, init) : old.fetch(url, init));+ let saved: { serverUrl: string; accessToken: string } | null = { serverUrl: SERVER, accessToken: old.accessToken };+ const vault = new BitwardenSecrets({ credentials: () => saved, fetch });+ let open!: () => void;+ old.state.gate = new Promise((done) => { open = done; });+ try {+ const oldList = vault.refresh();+ saved = null;+ vault.clear();+ saved = { serverUrl: "https://bw.example.test", accessToken: next.accessToken };+ expect((await vault.refresh()).items).toBe(1);+ expect(linkedSecrets(vault).map((secret) => secret.name)).toEqual(["NEXT_KEY"]);+ open();+ await oldList.catch(() => undefined);+ expect(linkedSecrets(vault).map((secret) => secret.name)).toEqual(["NEXT_KEY"]);+ } finally { open(); }+ });+it("reads a login only from the note's url: or site: lines, its username and 2FA key", () => {expect(loginFromNote("Site: example.com\nUSERNAME: [email protected]\nurl: https://login.example.com/x")).toEqual({ hosts: ["example.com", "login.example.com"], username: "[email protected]", totp: null });expect(loginFromNote("username: someone\njust words")).toBeNull();diff --git a/server/host/bitwarden-secrets.ts b/server/host/bitwarden-secrets.tsindex 71ca256dc8..957459f4cf 100644--- a/server/host/bitwarden-secrets.ts+++ b/server/host/bitwarden-secrets.ts@@ -120,6 +120,7 @@ export class BitwardenSecrets implements VaultProvider {/** Checks a new connection by reading its list; it replaces the current one only once `save` has kept its token. */async connect(candidate: BitwardenSecretsCredentials, save: () => void): Promise<BitwardenSecretsStatus> {const generation = ++this.generation;+ this.refreshing = null;let catalog: Catalog;try { catalog = await this.catalog(candidate); }catch (error) { throw problemOf(error); }@@ -137,6 +138,7 @@ export class BitwardenSecrets implements VaultProvider {clear(): void {this.generation++;+ this.refreshing = null;this.client = null;this.logins = [];this.entries = new Map();@@ -240,8 +242,8 @@ export class BitwardenSecrets implements VaultProvider {if (login) {const secret = await this.secret(login.secretId);const note = secret ? loginFromNote(secret.note) : null;- // Security: the note may name another site by now; the password goes only to the site it still names.- if (!secret?.value || !note?.hosts.some((host) => loginSite(host) === login.site)) return {};+ // Security: the note may name another site or account by now; the password goes only to the site and username it still names.+ if (!secret?.value || note?.username !== login.username || !note.hosts.some((host) => loginSite(host) === login.site)) return {};return { password: secret.value, totp: parseTotpKey(note.totp) };}const id = itemId.startsWith(ID_PREFIX) ? itemId.slice(ID_PREFIX.length) : "";