From 7fcd371ce8c12b8d0fb33b5d7c1c0ed6bb12e5ce Mon Sep 17 00:00:00 2001 From: William Frank Monroy Mamani Date: Thu, 3 Dec 2026 12:19:22 -0600 Subject: [PATCH 1/7] fix(browser): keep no secret value as a default in taught and recorded flows - A card number or expiry field named like one (cardnumber, card_number) counts as a card field, as one with a cc- autocomplete does. - Teach mode and flow recording read the identity's vault values when they start and hold them in memory, so a vault value typed by hand keeps no default before browser_login runs. A value under 4 characters counts only as the whole of what was typed. - A taught vault sign-in takes in the user name typed into the same form on the same page, even with other steps between or after the password. - The person's submit is dropped only when browser_login will submit: the identity policy's autoSubmit false keeps it as a step. - In the page, a text area or editable element named like a secret reports only its length, as an input does. --- .changeset/teach-secrets.md | 7 + apps/docs/content/docs/browser/flows.mdx | 5 +- apps/docs/content/docs/browser/teach-mode.mdx | 20 +- packages/browser/src/host.ts | 10 +- packages/browser/src/live-server.ts | 12 +- packages/browser/src/recorder.ts | 49 ++++- packages/browser/src/replay.ts | 2 +- packages/browser/src/sensitive.ts | 9 + packages/browser/src/teach.ts | 163 +++++++++++--- packages/browser/src/vault.ts | 53 +++++ .../test/helpers/memory-secret-store.ts | 14 ++ packages/browser/test/recorder.test.ts | 49 ++++- packages/browser/test/sensitive.test.ts | 17 ++ packages/browser/test/teach.test.ts | 208 ++++++++++++++++++ 14 files changed, 570 insertions(+), 48 deletions(-) create mode 100644 .changeset/teach-secrets.md create mode 100644 packages/browser/test/helpers/memory-secret-store.ts create mode 100644 packages/browser/test/teach.test.ts diff --git a/.changeset/teach-secrets.md b/.changeset/teach-secrets.md new file mode 100644 index 00000000..ca7549d4 --- /dev/null +++ b/.changeset/teach-secrets.md @@ -0,0 +1,7 @@ +--- +"turno-browser": patch +--- + +Teach mode and flow recording: a card number or expiry field named like one (`cardnumber`, `card_number`, `ccNum`, `card-expiry`) now counts as a card field without an `autocomplete` value, so a flow keeps no value for it. The vault's values are read from the secret store when teach mode or a recording starts and held in memory only, so a vault value typed by hand keeps no default before `browser_login` has run; a value of fewer than 4 characters counts only when it is the whole of what was typed. + +A taught vault sign-in now takes in the fields of its form that `browser_login` fills (the user name) typed into on that page, even with other steps between or after the password, and the person's own submit is dropped only when `browser_login` will submit: with the identity's policy at `"autoSubmit": false` the submit stays a step. In the page, a text area or an editable element named like a secret now reports only its length, as an input does. diff --git a/apps/docs/content/docs/browser/flows.mdx b/apps/docs/content/docs/browser/flows.mdx index 191b2652..75aff6cb 100644 --- a/apps/docs/content/docs/browser/flows.mdx +++ b/apps/docs/content/docs/browser/flows.mdx @@ -63,8 +63,9 @@ A refusal costs the agent one look at the page; a wrong element costs a wrong ac Text typed into a field becomes a parameter, with what was typed as its default. A sensitive one keeps no value: a password field, a one-time code or card field, a field named like `password`, -`otp`, `pin` or `token`, a vault value typed by hand, or any parameter the agent lists in -`sensitive` when it stops. A vault sign-in is a `browser_login` step with the site name only. +`otp`, `pin`, `token` or `cardnumber`, a vault value typed by hand (the vault's values are read +before the first typed step is kept, and a value of fewer than 4 characters counts only as the +whole of what was typed), or any parameter the agent lists in `sensitive` when it stops. A vault sign-in is a `browser_login` step with the site name only. Replay needs the sensitive values again; a value written `keychain:` is read from the secret store (`turno-browser secret set `), so the agent never sees it. Into a password or one-time code field an agent's `browser_replay` types only such a value; a plain one is refused diff --git a/apps/docs/content/docs/browser/teach-mode.mdx b/apps/docs/content/docs/browser/teach-mode.mdx index d7bf1146..f2f985c8 100644 --- a/apps/docs/content/docs/browser/teach-mode.mdx +++ b/apps/docs/content/docs/browser/teach-mode.mdx @@ -56,12 +56,20 @@ The rules for values are those of `browser_record`: - What you type is a parameter, with what you typed as its default. The review can make it a fixed value instead, or a parameter with no value kept. -- A password, a one-time code (also a field named only `code` in a sign-in form), a card number, - a field named like one, or a value of the - [vault](/docs/browser/vault) never keeps its value: the flow asks for it at each run, and the - review cannot make it fixed. -- A sign-in on a site of the vault is one `browser_login` step with the site's name: the fields you - typed into become that step, and your own submit is dropped when the vault submits. +- A password, a one-time code (also a field named only `code` in a sign-in form), a card number + or expiry (by its `autocomplete` or by a name such as `cardnumber` or `card_number`), a field + named like one, or a value of the [vault](/docs/browser/vault) never keeps its value: the flow + asks for it at each run, and the review cannot make it fixed. The vault's values are read when + teach mode starts and held in memory only, so one you type by hand is known from the first step. + A vault value of fewer than 4 characters counts only when it is the whole of what you typed. +- A sign-in on a site of the vault is one `browser_login` step with the site's name: the fields of + that form it fills (the user name, the password, a one-time code) that you typed into on that + page become that step, even with other steps between (a box checked, a key), and so does typing + into them afterwards. Another field of the form, and typing on an earlier page (the first step + of a sign-in in two pages), stay steps of their own. +- Your own submit (the click on the sign-in button, or Enter) is dropped when `browser_login` + submits the form itself. When it does not (the vault's `submit` is `confirm`, or the identity's + policy has `"autoSubmit": false`), your submit stays a step, so the flow still signs in. - Addresses keep no query string or fragment (they can carry tokens). ## Review and save diff --git a/packages/browser/src/host.ts b/packages/browser/src/host.ts index a53c3102..0539497d 100644 --- a/packages/browser/src/host.ts +++ b/packages/browser/src/host.ts @@ -613,7 +613,12 @@ class SessionBackend extends EventEmitter implements ServerBackend { const key = session ?? DIRECT_SESSION; let recorder = this.recorders.get(key); if (!recorder) { - recorder = new FlowRecorder(identity, this.host.redactor, () => this.recordSettings?.flows === true); + recorder = new FlowRecorder( + identity, + this.host.redactor, + () => this.recordSettings?.flows === true, + this.host.vaultStore, + ); this.recorders.set(key, recorder); } return recorder; @@ -1649,7 +1654,7 @@ class SessionBackend extends EventEmitter implements ServerBackend { const result = await tool.handle(context, parsed.params); if (stock) this.watch.follow(session ?? DIRECT_SESSION, stock.currentPage()); if (name === "browser_login") { - if (!result.isError) recorder?.record("browser_login", { site: parsed.params.site }); + if (!result.isError) await recorder?.record("browser_login", { site: parsed.params.site }); await recording?.afterStep({ tool: name, ok: !result.isError, screenshot: false }); } return unchosenNow ? this.withUserTabNote(result, unchosenNow(), json) : result; @@ -2808,6 +2813,7 @@ function liveServerFor( policy, guard, redactor, + ...(options.vaultStore ? { vaultStore: options.vaultStore } : {}), headless: options.config.browser.launchOptions?.headless === true, // Before a launch, the engine identity.json and the flags would pick. viewRefusal: (engine) => { diff --git a/packages/browser/src/live-server.ts b/packages/browser/src/live-server.ts index 752ab60e..56611eba 100644 --- a/packages/browser/src/live-server.ts +++ b/packages/browser/src/live-server.ts @@ -5,6 +5,7 @@ import type { AddressInfo } from "node:net"; import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; import { replaceFileSync } from "turno-core/paths"; +import type { SecretStore } from "turno-core/secrets"; import type { BrowserContext, CDPSession, Page } from "patchright-core"; import type { IdentityRef } from "./engine.js"; import { @@ -118,6 +119,8 @@ export interface LiveServerOptions { policy: LivePolicy; guard: VaultGuard; redactor: Redactor; + /** The secret store teach mode reads the vault's values from (tests inject a fake); default: this machine's. */ + vaultStore?: SecretStore; headless: boolean; /** Why the engine shows no pixels; `engine` is the running one, undefined before a launch. */ viewRefusal(engine: string | undefined): string | undefined; @@ -912,7 +915,14 @@ export class LiveServer implements BrowserWatch { } finally { this.teachStarting = false; } - const session = new TeachSession(b.context, this.o.identity, this.o.redactor, name, () => this.pushTeach()); + const session = new TeachSession( + b.context, + this.o.identity, + this.o.redactor, + name, + () => this.pushTeach(), + this.o.vaultStore, + ); // `overwrite` given at the start holds for the save, which the panel or Enter asks for later. this.teaching = { session, phase: "teaching", held, overwrite }; try { diff --git a/packages/browser/src/recorder.ts b/packages/browser/src/recorder.ts index ce1fc1b2..0e6f8865 100644 --- a/packages/browser/src/recorder.ts +++ b/packages/browser/src/recorder.ts @@ -19,9 +19,11 @@ import { writeFlow, } from "./flows.js"; import { existsSync } from "node:fs"; +import type { SecretStore } from "turno-core/secrets"; import { ActionCache, actionCachePath, differences, fingerprintOf, redactFingerprint, refusal } from "./fingerprint.js"; import type { Redactor } from "./redact.js"; import { secretField } from "./sensitive.js"; +import { VaultValues, vaultValues } from "./vault.js"; import type { TurnoTool } from "./tools.js"; import { type ToolSchema, upstream } from "./upstream.js"; @@ -35,9 +37,10 @@ import { type ToolSchema, upstream } from "./upstream.js"; * * - Typed text is always a parameter. It keeps what was typed as its default only when the * field is not sensitive: a password field, an `autocomplete` of a password, a one-time code - * or a card, a field named like one (`password`, `otp`, `pin`, `cvv`, `token`...), or a value - * that is one of this server's vault values. The agent can mark more parameters sensitive - * when it stops a named recording, which is held in memory until then. + * or a card, a field named like one (`password`, `otp`, `pin`, `cvv`, `token`, `cardnumber`...), + * or a value of the identity's vault. The vault's values are read from the secret store before + * the first typed step is kept, and held in memory only. The agent can mark more parameters + * sensitive when it stops a named recording, which is held in memory until then. * - `browser_login` is recorded as its site name; the values are read from the vault again * at replay. * - Nothing else of a page (snapshots, results, values of other fields) is stored. @@ -332,6 +335,8 @@ export class FlowRecorder { private overwrite = false; private auto: Draft | undefined; private suspended = 0; + /** The vault's values, read once per named recording (and once for the identity's own). */ + private vaultLoad: Promise | undefined; /** The fingerprints of what the identity's actions worked on (`fingerprint.ts`). */ readonly cache: ActionCache; @@ -341,6 +346,8 @@ export class FlowRecorder { private readonly redactor: Redactor, /** identity.json `record.flows`: record every session as `auto-