rechrome 1.41.0 → 1.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -97,6 +97,25 @@ browser writes it, not before (downloads wait for the scrub). The check reads th
97
97
  the snapshot, so a page script that clears or replaces a neutrally-labelled password field in
98
98
  between can slip past; closing that needs redaction inside playwright's snapshot code. Not yet supported on a Windows daemon.
99
99
 
100
+ #### Copying a secret out of a page: `read-secret`
101
+
102
+ The reverse of `fill-secret`, for moving a secret that a page shows (an app's signing
103
+ secret, an API key) into a vault without it appearing anywhere:
104
+
105
+ ```bash
106
+ rech read-secret e12 --allow-domain api.example.com | vault-put my-app/signing-secret
107
+ ```
108
+
109
+ - `--allow-domain` is required. The field's own page host must match it.
110
+ - The value goes back in its own response field. It is never in a log line, a file or
111
+ another command's output, and is masked in every later output.
112
+ - stdout must be a pipe: a terminal or a file redirect is refused before the host is asked.
113
+ - A label ref means its input, as with `fill`. A non-field element gives its text.
114
+ - On a shared (scoped) listener it is off until the host runs
115
+ `rech listener set <listener> --read-secrets`. Each read is logged without the value.
116
+ Turn it on only for links you trust with every account in their profiles: the caller picks
117
+ `--allow-domain`, so the link can read any field it can reach, saved passwords included.
118
+
100
119
  ### 3. Where things are kept
101
120
 
102
121
  | Where | What |
package/fill-secret.js CHANGED
@@ -332,6 +332,108 @@ async function runCodeOnSession(opts) {
332
332
  function fillSecretOnSession(opts) {
333
333
  return runCodeOnSession({ ...opts, code: buildFillCode(opts.ref, opts.value, opts.allowDomains, opts.submit) });
334
334
  }
335
+ var READ_SECRET_USAGE = `Usage: rech read-secret <ref|selector> --allow-domain <glob> [--allow-domain <glob>]... | <vault command>
336
+ Writes the field's current value, raw and without a newline, to stdout, which must be a pipe
337
+ into the program that stores it (never a terminal or a file). The value is never logged and
338
+ is masked in later outputs.
339
+ --allow-domain GLOB required: refuse unless the field's page host matches, e.g. app.slack.com`;
340
+ function parseReadSecretArgs(args) {
341
+ const [cmd, ...rest] = args;
342
+ if (cmd !== "read-secret")
343
+ throw new Error("Expected read-secret");
344
+ let ref;
345
+ const allowDomains = [];
346
+ for (let i = 0;i < rest.length; i++) {
347
+ const a = rest[i];
348
+ if (a === "--allow-domain" || a.startsWith("--allow-domain=")) {
349
+ const v = a === "--allow-domain" ? rest[++i] : a.slice("--allow-domain=".length);
350
+ if (!v)
351
+ throw new Error("--allow-domain got an empty host");
352
+ for (const d of v.split(",")) {
353
+ domainGlobToRegExp(d.trim());
354
+ allowDomains.push(d.trim());
355
+ }
356
+ } else if (a.startsWith("-"))
357
+ throw new Error(`read-secret: unknown option ${a}`);
358
+ else if (ref === undefined)
359
+ ref = a;
360
+ else
361
+ throw new Error("read-secret takes one target");
362
+ }
363
+ if (!ref)
364
+ throw new Error("read-secret needs a target ref (from rech snapshot) or a selector");
365
+ if (!allowDomains.length)
366
+ throw new Error("read-secret needs --allow-domain: name the site the secret must come from");
367
+ return { ref, allowDomains };
368
+ }
369
+ function readSecretWireArgs(req) {
370
+ return ["read-secret", req.ref, ...req.allowDomains.map((d) => `--allow-domain=${d}`)];
371
+ }
372
+ function parseReadSecretWire(args) {
373
+ const [cmd, ref, ...rest] = args;
374
+ if (cmd !== "read-secret" || !ref || ref.startsWith("-"))
375
+ throw new Error("read-secret needs a target ref");
376
+ const allowDomains = [];
377
+ for (const a of rest) {
378
+ if (!a.startsWith("--allow-domain="))
379
+ throw new Error(`read-secret: unexpected argument ${a.startsWith("-") ? a : "(positional)"}`);
380
+ const d = a.slice("--allow-domain=".length);
381
+ domainGlobToRegExp(d);
382
+ allowDomains.push(d);
383
+ }
384
+ if (!allowDomains.length)
385
+ throw new Error("read-secret needs --allow-domain");
386
+ return { ref, allowDomains };
387
+ }
388
+ function buildReadCode(ref, allowDomains) {
389
+ const patterns = allowDomains.map((d) => domainGlobToRegExp(d).source);
390
+ const locator = /^(f\d+)?e\d+$/.test(ref) ? `page.locator(${JSON.stringify(`aria-ref=${ref}`)})` : `page.locator(${JSON.stringify(ref)})`;
391
+ return `async page => {
392
+ const el = await ${locator}.elementHandle({ timeout: 10000 });
393
+ try {
394
+ const host = String(await el.evaluate(e => e.ownerDocument.location.hostname)).toLowerCase();
395
+ const allowed = ${JSON.stringify(patterns)};
396
+ if (!allowed.some(p => new RegExp(p, "i").test(host)))
397
+ throw new Error("read-secret refused: the field's page host " + JSON.stringify(host) + " is not allowed by --allow-domain");
398
+ // Like fill: a label ref means its control. A field reads as its value; anything else (a
399
+ // secret shown as text after "Show") as its text.
400
+ // A page getter can throw an error that quotes the value: report a fixed message instead.
401
+ let value;
402
+ try {
403
+ value = await el.evaluate(e => {
404
+ const t = e.tagName === "LABEL" && e.control ? e.control : e;
405
+ return t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.tagName === "SELECT" ? String(t.value) : String(t.textContent ?? "").trim();
406
+ });
407
+ } catch { throw new Error("read-secret: could not read the field"); }
408
+ return JSON.stringify({ host, value });
409
+ } finally {
410
+ await el.dispose().catch(() => {});
411
+ }
412
+ }`;
413
+ }
414
+ async function readSecretOnSession(opts) {
415
+ const { isError, text } = await runCodeOnSession({ ...opts, code: buildReadCode(opts.ref, opts.allowDomains), json: true });
416
+ if (isError)
417
+ throw new Error(text.match(/read-secret refused: [^\n]*/)?.[0] ?? (/no browser is open|could not reach/.test(text) ? text.trim().split(`
418
+ `)[0] : "read-secret: could not read the field (is the ref from a fresh rech snapshot?)"));
419
+ let raw;
420
+ try {
421
+ raw = JSON.parse(text).result;
422
+ } catch {
423
+ raw = text.match(/### Result\n([^\n]*)/)?.[1];
424
+ }
425
+ let out = raw;
426
+ for (let i = 0;i < 2 && typeof out === "string"; i++) {
427
+ try {
428
+ out = JSON.parse(out);
429
+ } catch {
430
+ out = undefined;
431
+ }
432
+ }
433
+ if (!out || typeof out.host !== "string" || typeof out.value !== "string")
434
+ throw new Error("read-secret: the page returned no value");
435
+ return out;
436
+ }
335
437
  var PASSWORD_FIELDS = 'input[type=password], input[autocomplete~="current-password" i], input[autocomplete~="new-password" i], input[name*="pass" i], input[id*="pass" i]';
336
438
  var PASSWORD_VALUES_CODE = `async page => {
337
439
  const values = [];
@@ -381,11 +483,13 @@ function maskPasswordLines(text) {
381
483
  export {
382
484
  FILL_SECRET_USAGE,
383
485
  MIN_MASK_LENGTH,
486
+ READ_SECRET_USAGE,
384
487
  SECRET_MASK,
385
488
  SECRET_MASK_TTL_MS,
386
489
  SecretMasker,
387
490
  base32Decode,
388
491
  buildFillCode,
492
+ buildReadCode,
389
493
  daemonSessionSockets,
390
494
  domainGlobToRegExp,
391
495
  fillSecretOnSession,
@@ -397,9 +501,13 @@ export {
397
501
  parseDotenv,
398
502
  parseFillSecretArgs,
399
503
  parseFillSecretWire,
504
+ parseReadSecretArgs,
505
+ parseReadSecretWire,
400
506
  parseScanResult,
401
507
  passwordValuesOnSession,
508
+ readSecretOnSession,
402
509
  readSecretSource,
510
+ readSecretWireArgs,
403
511
  runCodeOnSession,
404
512
  sessionSocketCandidates,
405
513
  socketRequest,
package/fill-secret.ts CHANGED
@@ -348,6 +348,101 @@ export function fillSecretOnSession(opts: { socketRoot: string; session: string;
348
348
  return runCodeOnSession({ ...opts, code: buildFillCode(opts.ref, opts.value, opts.allowDomains, opts.submit) });
349
349
  }
350
350
 
351
+ // ---------- read-secret: a field's value to a pipe ----------
352
+ //
353
+ // The reverse of fill-secret, for moving a secret a page shows (an API signing secret in a
354
+ // password-type field) into a vault without it appearing anywhere. The page host must match a
355
+ // required --allow-domain; the value travels only in the response's `secretOut` field, is never
356
+ // logged, is masked in every later output, and the client writes it raw to a pipe only, never
357
+ // to a terminal. On a profile-scoped listener it is refused unless the host turned it on.
358
+
359
+ export const READ_SECRET_USAGE = `Usage: rech read-secret <ref|selector> --allow-domain <glob> [--allow-domain <glob>]... | <vault command>
360
+ Writes the field's current value, raw and without a newline, to stdout, which must be a pipe
361
+ into the program that stores it (never a terminal or a file). The value is never logged and
362
+ is masked in later outputs.
363
+ --allow-domain GLOB required: refuse unless the field's page host matches, e.g. app.slack.com`;
364
+
365
+ /** Client args → the wire args (same shape); --allow-domain is required. */
366
+ export function parseReadSecretArgs(args: string[]): { ref: string; allowDomains: string[] } {
367
+ const [cmd, ...rest] = args;
368
+ if (cmd !== "read-secret") throw new Error("Expected read-secret");
369
+ let ref: string | undefined;
370
+ const allowDomains: string[] = [];
371
+ for (let i = 0; i < rest.length; i++) {
372
+ const a = rest[i]!;
373
+ if (a === "--allow-domain" || a.startsWith("--allow-domain=")) {
374
+ const v = a === "--allow-domain" ? rest[++i] : a.slice("--allow-domain=".length);
375
+ if (!v) throw new Error("--allow-domain got an empty host");
376
+ for (const d of v.split(",")) { domainGlobToRegExp(d.trim()); allowDomains.push(d.trim()); }
377
+ } else if (a.startsWith("-")) throw new Error(`read-secret: unknown option ${a}`);
378
+ else if (ref === undefined) ref = a;
379
+ else throw new Error("read-secret takes one target");
380
+ }
381
+ if (!ref) throw new Error("read-secret needs a target ref (from rech snapshot) or a selector");
382
+ if (!allowDomains.length) throw new Error("read-secret needs --allow-domain: name the site the secret must come from");
383
+ return { ref, allowDomains };
384
+ }
385
+
386
+ export function readSecretWireArgs(req: { ref: string; allowDomains: string[] }): string[] {
387
+ return ["read-secret", req.ref, ...req.allowDomains.map(d => `--allow-domain=${d}`)];
388
+ }
389
+
390
+ /** Parse what the daemon received; exactly the shape readSecretWireArgs sends. */
391
+ export function parseReadSecretWire(args: string[]): { ref: string; allowDomains: string[] } {
392
+ const [cmd, ref, ...rest] = args;
393
+ if (cmd !== "read-secret" || !ref || ref.startsWith("-")) throw new Error("read-secret needs a target ref");
394
+ const allowDomains: string[] = [];
395
+ for (const a of rest) {
396
+ if (!a.startsWith("--allow-domain=")) throw new Error(`read-secret: unexpected argument ${a.startsWith("-") ? a : "(positional)"}`);
397
+ const d = a.slice("--allow-domain=".length);
398
+ domainGlobToRegExp(d);
399
+ allowDomains.push(d);
400
+ }
401
+ if (!allowDomains.length) throw new Error("read-secret needs --allow-domain");
402
+ return { ref, allowDomains };
403
+ }
404
+
405
+ /** run-code that checks the field's own document host, then returns {host, value} as JSON. */
406
+ export function buildReadCode(ref: string, allowDomains: string[]): string {
407
+ const patterns = allowDomains.map(d => domainGlobToRegExp(d).source);
408
+ const locator = /^(f\d+)?e\d+$/.test(ref) ? `page.locator(${JSON.stringify(`aria-ref=${ref}`)})` : `page.locator(${JSON.stringify(ref)})`;
409
+ return `async page => {
410
+ const el = await ${locator}.elementHandle({ timeout: 10000 });
411
+ try {
412
+ const host = String(await el.evaluate(e => e.ownerDocument.location.hostname)).toLowerCase();
413
+ const allowed = ${JSON.stringify(patterns)};
414
+ if (!allowed.some(p => new RegExp(p, "i").test(host)))
415
+ throw new Error("read-secret refused: the field's page host " + JSON.stringify(host) + " is not allowed by --allow-domain");
416
+ // Like fill: a label ref means its control. A field reads as its value; anything else (a
417
+ // secret shown as text after "Show") as its text.
418
+ // A page getter can throw an error that quotes the value: report a fixed message instead.
419
+ let value;
420
+ try {
421
+ value = await el.evaluate(e => {
422
+ const t = e.tagName === "LABEL" && e.control ? e.control : e;
423
+ return t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.tagName === "SELECT" ? String(t.value) : String(t.textContent ?? "").trim();
424
+ });
425
+ } catch { throw new Error("read-secret: could not read the field"); }
426
+ return JSON.stringify({ host, value });
427
+ } finally {
428
+ await el.dispose().catch(() => {});
429
+ }
430
+ }`;
431
+ }
432
+
433
+ /** Read the field on the session's live browser. The returned value must never be logged. */
434
+ export async function readSecretOnSession(opts: { socketRoot: string; session: string; cwd: string; ref: string; allowDomains: string[] }): Promise<{ host: string; value: string }> {
435
+ const { isError, text } = await runCodeOnSession({ ...opts, code: buildReadCode(opts.ref, opts.allowDomains), json: true });
436
+ // Pass on only the messages this code writes itself (they hold the host, never the value).
437
+ if (isError) throw new Error(text.match(/read-secret refused: [^\n]*/)?.[0] ?? (/no browser is open|could not reach/.test(text) ? text.trim().split("\n")[0]! : "read-secret: could not read the field (is the ref from a fresh rech snapshot?)"));
438
+ let raw: unknown;
439
+ try { raw = JSON.parse(text).result; } catch { raw = text.match(/### Result\n([^\n]*)/)?.[1]; }
440
+ let out: any = raw;
441
+ for (let i = 0; i < 2 && typeof out === "string"; i++) { try { out = JSON.parse(out); } catch { out = undefined; } }
442
+ if (!out || typeof out.host !== "string" || typeof out.value !== "string") throw new Error("read-secret: the page returned no value");
443
+ return out;
444
+ }
445
+
351
446
  // ---------- password fields in snapshots ----------
352
447
  //
353
448
  // Snapshots print every input's value, and that includes password fields Chrome autofilled
package/listeners.js CHANGED
@@ -76,6 +76,8 @@ function validateListeners(value) {
76
76
  }
77
77
  if (l.uploads !== undefined && l.uploads !== false)
78
78
  validateUploadPolicy(l.uploads);
79
+ if (l.readSecrets !== undefined && typeof l.readSecrets !== "boolean")
80
+ throw new Error("readSecrets must be true or false");
79
81
  const address = listenerAddress(l);
80
82
  if (names.has(l.name) || addresses.has(address) || keys.has(l.key))
81
83
  throw new Error("Listener names, addresses, and credentials must be unique");
@@ -130,9 +132,11 @@ function authorizeProfileRequest(listener, body) {
130
132
  const args = body.args.filter((a) => /^-s=[a-zA-Z0-9_-]{1,64}$/.test(a) === false);
131
133
  if (args[0] === "upload" && listener.uploads === false)
132
134
  throw new Error(`Uploads are off on listener "${listener.name}". The host can turn them on: rech listener set ${listener.name} --uploads`);
133
- if (args[0] !== "upload" && !SCOPED_COMMANDS.has(args[0]))
135
+ if (args[0] === "read-secret" && listener.readSecrets !== true)
136
+ throw new Error(`read-secret is off on listener "${listener.name}". The host can turn it on: rech listener set ${listener.name} --read-secrets`);
137
+ if (args[0] !== "upload" && args[0] !== "read-secret" && !SCOPED_COMMANDS.has(args[0]))
134
138
  throw new Error("Command is unavailable on profile-scoped listeners; use the local management listener for arbitrary code or host access");
135
- if (body.args.filter((a) => a.startsWith("-s=")).length > 1 || args.slice(1).some((a) => a.startsWith("-") && !(args[0] === "screenshot" && a === "--full-page") && !(args[0] === "console" && a === "--clear") && !(args[0] === "fill-secret" && (a === "--submit" || a === "--totp" || a.startsWith("--allow-domain=")))))
139
+ if (body.args.filter((a) => a.startsWith("-s=")).length > 1 || args.slice(1).some((a) => a.startsWith("-") && !(args[0] === "screenshot" && a === "--full-page") && !(args[0] === "console" && a === "--clear") && !(args[0] === "fill-secret" && (a === "--submit" || a === "--totp" || a.startsWith("--allow-domain="))) && !(args[0] === "read-secret" && a.startsWith("--allow-domain="))))
136
140
  throw new Error("CLI option overrides are unavailable on profile-scoped listeners");
137
141
  if (["open", "goto", "tab-new"].includes(args[0]) && args[1] && !/^https?:\/\//i.test(args[1]) && args[1] !== "about:blank")
138
142
  throw new Error("Scoped navigation accepts only HTTP(S) or about:blank");
package/listeners.ts CHANGED
@@ -6,7 +6,7 @@ import { join } from "path";
6
6
  import { mkdir, readFile, rename, writeFile } from "fs/promises";
7
7
 
8
8
  // publicUrl: where a reverse proxy (Tailscale Serve, Caddy, nginx, ...) exposes this listener.
9
- export type Listener = { name: string; host: string; port: number; key: string; profiles: string[] | "*"; prefix?: string; publicUrl?: string; uploads?: UploadPolicy | false };
9
+ export type Listener = { name: string; host: string; port: number; key: string; profiles: string[] | "*"; prefix?: string; publicUrl?: string; uploads?: UploadPolicy | false; readSecrets?: boolean };
10
10
  // retiredPorts: ports of removed listeners, newest last. New listeners skip them so a link
11
11
  // saved for a removed listener gets "connection refused", not some other listener's answer.
12
12
  export type ListenerConfig = { version: 1; listeners: Listener[]; retiredPorts?: number[] };
@@ -61,6 +61,7 @@ export function validateListeners(value: unknown): ListenerConfig {
61
61
  // Uploads are on unless set to false: the client sends file bytes it already has, and the
62
62
  // host never reads a path for them.
63
63
  if (l.uploads !== undefined && l.uploads !== false) validateUploadPolicy(l.uploads);
64
+ if (l.readSecrets !== undefined && typeof l.readSecrets !== "boolean") throw new Error("readSecrets must be true or false");
64
65
  const address = listenerAddress(l);
65
66
  if (names.has(l.name) || addresses.has(address) || keys.has(l.key)) throw new Error("Listener names, addresses, and credentials must be unique");
66
67
  names.add(l.name); addresses.add(address); keys.add(l.key);
@@ -107,8 +108,10 @@ export function authorizeProfileRequest(listener: Listener, body: any): string {
107
108
  const args = body.args.filter((a: string) => /^-s=[a-zA-Z0-9_-]{1,64}$/.test(a) === false);
108
109
  if (args[0] === "upload" && listener.uploads === false)
109
110
  throw new Error(`Uploads are off on listener "${listener.name}". The host can turn them on: rech listener set ${listener.name} --uploads`);
110
- if (args[0] !== "upload" && !SCOPED_COMMANDS.has(args[0])) throw new Error("Command is unavailable on profile-scoped listeners; use the local management listener for arbitrary code or host access");
111
- if (body.args.filter((a: string) => a.startsWith("-s=")).length > 1 || args.slice(1).some((a: string) => a.startsWith("-") && !(args[0] === "screenshot" && a === "--full-page") && !(args[0] === "console" && a === "--clear") && !(args[0] === "fill-secret" && (a === "--submit" || a === "--totp" || a.startsWith("--allow-domain="))))) throw new Error("CLI option overrides are unavailable on profile-scoped listeners");
111
+ if (args[0] === "read-secret" && listener.readSecrets !== true)
112
+ throw new Error(`read-secret is off on listener "${listener.name}". The host can turn it on: rech listener set ${listener.name} --read-secrets`);
113
+ if (args[0] !== "upload" && args[0] !== "read-secret" && !SCOPED_COMMANDS.has(args[0])) throw new Error("Command is unavailable on profile-scoped listeners; use the local management listener for arbitrary code or host access");
114
+ if (body.args.filter((a: string) => a.startsWith("-s=")).length > 1 || args.slice(1).some((a: string) => a.startsWith("-") && !(args[0] === "screenshot" && a === "--full-page") && !(args[0] === "console" && a === "--clear") && !(args[0] === "fill-secret" && (a === "--submit" || a === "--totp" || a.startsWith("--allow-domain="))) && !(args[0] === "read-secret" && a.startsWith("--allow-domain=")))) throw new Error("CLI option overrides are unavailable on profile-scoped listeners");
112
115
  if (["open", "goto", "tab-new"].includes(args[0]) && args[1] && !/^https?:\/\//i.test(args[1]) && args[1] !== "about:blank") throw new Error("Scoped navigation accepts only HTTP(S) or about:blank");
113
116
  // Upload is handled by the byte-only receiver; the caller cannot supply host paths.
114
117
  if (args[0] === "upload" && (args.length !== 1 || !body.upload)) throw new Error("Upload requires stdin bytes; host paths are unavailable");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rechrome",
3
- "version": "1.41.0",
3
+ "version": "1.42.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/snomiao/rechrome.git"
package/rechrome.js CHANGED
@@ -6,9 +6,9 @@ import { file } from "bun";
6
6
  import yargs from "yargs";
7
7
  import { readExtensionTokenFromProfile } from "./extension-token.js";
8
8
  import { redact } from "./redact.js";
9
- import { FILL_SECRET_USAGE, SECRET_MASK, parseFillSecretArgs, fillSecretWireArgs, readSecretSource, totpCode, totpWaitMs } from "./fill-secret.js";
9
+ import { READ_SECRET_USAGE, parseReadSecretArgs, readSecretWireArgs, FILL_SECRET_USAGE, SECRET_MASK, parseFillSecretArgs, fillSecretWireArgs, readSecretSource, totpCode, totpWaitMs } from "./fill-secret.js";
10
10
  import { createHash, randomBytes } from "crypto";
11
- import { mkdirSync, appendFileSync, existsSync, realpathSync, accessSync, cpSync, unlinkSync, readFileSync, readdirSync, renameSync, readlinkSync, rmdirSync, constants as fsConstants } from "fs";
11
+ import { mkdirSync, fstatSync, appendFileSync, existsSync, realpathSync, accessSync, cpSync, unlinkSync, readFileSync, readdirSync, renameSync, readlinkSync, rmdirSync, constants as fsConstants } from "fs";
12
12
  import { hostname, homedir, networkInterfaces } from "os";
13
13
  import { isIPv4 } from "net";
14
14
  import { join, basename, dirname, resolve } from "path";
@@ -1932,7 +1932,7 @@ async function callServe(
1932
1932
  throwOnFailure = false,
1933
1933
  upload?: UploadPayload,
1934
1934
  secret?: string,
1935
- ): Promise<{ status: number; stdout: string; stderr: string; files?: string[]; existingSession?: boolean }> {
1935
+ ): Promise<{ status: number; stdout: string; stderr: string; files?: string[]; existingSession?: boolean; secretOut?: string }> {
1936
1936
  const { key, host, port, protocol, extensionId, extensionToken, profileDirectory, userDataDir, loadExtension } = parseUrl(url);
1937
1937
  // Reuse the caller's identity when provided — computing it shells out to `git` several times,
1938
1938
  // and run() has already done so for its log line. Recomputing here would double those git
@@ -2169,6 +2169,29 @@ async function run(url: string, args: string[], overrideEnv?: Record<string, str
2169
2169
  let secret: string | undefined;
2170
2170
  let upload: UploadPayload | undefined;
2171
2171
  const cmdIdx = args.findIndex(a => !a.startsWith("-s="));
2172
+ if (args[cmdIdx] === "read-secret") {
2173
+ if (args.some(a => a === "--help" || a === "-h")) { console.log(READ_SECRET_USAGE); process.exit(0); }
2174
+ let wire: string[];
2175
+ try {
2176
+ // Only a pipe: a terminal would show the secret, and a file would keep it. Checked before
2177
+ // asking the host for it.
2178
+ const out = fstatSync(1);
2179
+ if (!out.isFIFO() && !out.isSocket()) throw new Error("read-secret writes the secret to stdout, which must be a pipe into the program that stores it (not a terminal or a file)");
2180
+ wire = readSecretWireArgs(parseReadSecretArgs(args.slice(cmdIdx)));
2181
+ } catch (err) {
2182
+ console.error(`[rech] ${err instanceof Error ? err.message : String(err)}\n${READ_SECRET_USAGE}`);
2183
+ process.exit(2);
2184
+ }
2185
+ const res = await callServe(url, [...args.filter(a => a.startsWith("-s=")), ...wire], overrideEnv, identity);
2186
+ if (res.status !== 0 || typeof res.secretOut !== "string") {
2187
+ process.stderr.write(res.stderr || (res.status === 0 ? "[rech] read-secret: this daemon is older than the client (no value returned)\n" : ""));
2188
+ process.exit(res.status || 1);
2189
+ }
2190
+ // Wait until the pipe has taken all of it before exiting.
2191
+ await new Promise<void>((done, fail) => process.stdout.write(res.secretOut!, e => e ? fail(e) : done()));
2192
+ console.error(`[rech] read-secret: wrote ${res.secretOut.length} characters to stdout`);
2193
+ process.exit(0);
2194
+ }
2172
2195
  if (args[cmdIdx] === "fill-secret") {
2173
2196
  if (args.some(a => a === "--help" || a === "-h")) { console.log(FILL_SECRET_USAGE); process.exit(0); }
2174
2197
  try {
@@ -3345,7 +3368,7 @@ async function rotateKey(name: string): Promise<void> {
3345
3368
  console.log(`New key for ${name}; URLs carrying the old key stop working now. Print new ones with: rech share <profile> --listener ${name}`);
3346
3369
  }
3347
3370
 
3348
- async function setListener(name: string, opts: { publicUrl?: string; clearPublicUrl?: boolean; uploads?: boolean; hostUploadDirs?: string[]; noHostUploads?: boolean }): Promise<void> {
3371
+ async function setListener(name: string, opts: { publicUrl?: string; clearPublicUrl?: boolean; uploads?: boolean; hostUploadDirs?: string[]; noHostUploads?: boolean; readSecrets?: boolean }): Promise<void> {
3349
3372
  const config = await requireListeners();
3350
3373
  let listener = config.listeners.find(l => l.name === name);
3351
3374
  if (!listener) throw new Error(`Unknown listener "${name}". See rech listener ls.`);
@@ -3363,7 +3386,12 @@ async function setListener(name: string, opts: { publicUrl?: string; clearPublic
3363
3386
  else policy.hostDirs = [...new Set([...(policy.hostDirs ?? []), ...opts.hostUploadDirs!.map(d => realpathSync(resolve(d)))])];
3364
3387
  listener.uploads = policy;
3365
3388
  }
3389
+ if (opts.readSecrets !== undefined) {
3390
+ if (listener.profiles === "*") throw new Error(`"${name}" is the local management listener: read-secret is always available there.`);
3391
+ if (opts.readSecrets) listener.readSecrets = true; else delete listener.readSecrets;
3392
+ }
3366
3393
  await writeListeners(config);
3394
+ if (opts.readSecrets !== undefined) console.log(opts.readSecrets ? `${name}: read-secret on. Anyone with this link can copy the value of any field (saved passwords included) on any site its profiles have open; --allow-domain only checks the site the caller names. Each read is logged without the value` : `${name}: read-secret off`);
3367
3395
  if (opts.publicUrl !== undefined || opts.clearPublicUrl) console.log(listener.publicUrl ? `${name} is reachable at ${listener.publicUrl}` : `${name}: public URL cleared`);
3368
3396
  if (opts.hostUploadDirs?.length || opts.noHostUploads) {
3369
3397
  const dirs = (listener.uploads || {}).hostDirs;
@@ -4447,7 +4475,7 @@ export type RechHandlers = {
4447
4475
  allowListener(name: string, profiles: string[]): Promise<void>;
4448
4476
  denyListener(name: string, profiles: string[]): Promise<void>;
4449
4477
  rotateKey(name: string): Promise<void>;
4450
- setListener(name: string, opts: { publicUrl?: string; clearPublicUrl?: boolean; uploads?: boolean; hostUploadDirs?: string[]; noHostUploads?: boolean }): Promise<void>;
4478
+ setListener(name: string, opts: { publicUrl?: string; clearPublicUrl?: boolean; uploads?: boolean; hostUploadDirs?: string[]; noHostUploads?: boolean; readSecrets?: boolean }): Promise<void>;
4451
4479
  setup(opts: SetupOptions): Promise<void>;
4452
4480
  tray(action?: string): Promise<void>;
4453
4481
  provisionProfile(name: string, opts: { headed: boolean; experimental: boolean }): Promise<void>;
@@ -4480,6 +4508,8 @@ const HELP_EPILOGUE = `Browser commands (sent to this project's Chrome session):
4480
4508
  --isolate in a throwaway session, e.g. for a login flow
4481
4509
  rech fill-secret <ref> --from-env VAR | --totp-from-env VAR [--env-file f] [--allow-domain '*.example.com']
4482
4510
  type a password / TOTP code without it reaching argv, logs or output
4511
+ rech read-secret <ref> --allow-domain <host> | <vault command>
4512
+ copy a field's value (e.g. an API secret) into a pipe, never shown or logged
4483
4513
  rech pw <args> forward verbatim to playwright-cli, e.g. \`rech pw --version\`
4484
4514
  rech --version rechrome's version
4485
4515
 
@@ -4595,9 +4625,10 @@ export function rechCli(argv: string[], handlers: RechHandlers) {
4595
4625
  .option("clear-public-url", { type: "boolean", conflicts: "public-url" })
4596
4626
  .option("uploads", { type: "boolean", describe: "Uploads of images the link holder sends (rech upload) are on by default; --no-uploads turns them off" })
4597
4627
  .option("host-upload-dir", { type: "string", array: true, requiresArg: true, describe: "Off by default. Also let links upload files already on this host, from inside this directory (rech upload --host <path>); repeatable" })
4628
+ .option("read-secrets", { type: "boolean", describe: "Off by default. Let this listener's links copy any field's value (saved passwords too) into a pipe (rech read-secret): only for links you trust with those accounts. --no-read-secrets turns it off" })
4598
4629
  .option("host-uploads", { type: "boolean", describe: "--no-host-uploads turns host-path uploads off again" })
4599
- .check(a => a.publicUrl !== undefined || a.clearPublicUrl || a.uploads !== undefined || a.hostUploadDir?.length || a.hostUploads === false ? true : "Pass --public-url <url>, --clear-public-url, --uploads/--no-uploads, or --host-upload-dir/--no-host-uploads"),
4600
- a => handlers.setListener(a.name, { publicUrl: a.publicUrl, clearPublicUrl: a.clearPublicUrl, ...(a.uploads !== undefined ? { uploads: a.uploads } : {}), ...(a.hostUploadDir?.length ? { hostUploadDirs: a.hostUploadDir as string[] } : {}), ...(a.hostUploads === false ? { noHostUploads: true } : {}) }))
4630
+ .check(a => a.publicUrl !== undefined || a.clearPublicUrl || a.uploads !== undefined || a.hostUploadDir?.length || a.hostUploads === false || a.readSecrets !== undefined ? true : "Pass --public-url <url>, --clear-public-url, --uploads/--no-uploads, or --host-upload-dir/--no-host-uploads"),
4631
+ a => handlers.setListener(a.name, { publicUrl: a.publicUrl, clearPublicUrl: a.clearPublicUrl, ...(a.uploads !== undefined ? { uploads: a.uploads } : {}), ...(a.hostUploadDir?.length ? { hostUploadDirs: a.hostUploadDir as string[] } : {}), ...(a.hostUploads === false ? { noHostUploads: true } : {}), ...(a.readSecrets !== undefined ? { readSecrets: a.readSecrets } : {}) }))
4601
4632
  .command("port [name]", "Print a listener's port (for a proxy command)", y => y.positional("name", { type: "string" }),
4602
4633
  a => handlers.listenerPort(a.name))
4603
4634
  .command("rotate-key <name>", "Give a listener a new key (old URLs stop working)", y => y.positional("name", { type: "string", demandOption: true }),
package/rechrome.ts CHANGED
@@ -6,9 +6,9 @@ import { file } from "bun";
6
6
  import yargs from "yargs";
7
7
  import { readExtensionTokenFromProfile } from "./extension-token.ts";
8
8
  import { redact } from "./redact.ts";
9
- import { FILL_SECRET_USAGE, SECRET_MASK, parseFillSecretArgs, fillSecretWireArgs, readSecretSource, totpCode, totpWaitMs } from "./fill-secret.ts";
9
+ import { READ_SECRET_USAGE, parseReadSecretArgs, readSecretWireArgs, FILL_SECRET_USAGE, SECRET_MASK, parseFillSecretArgs, fillSecretWireArgs, readSecretSource, totpCode, totpWaitMs } from "./fill-secret.ts";
10
10
  import { createHash, randomBytes } from "crypto";
11
- import { mkdirSync, appendFileSync, existsSync, realpathSync, accessSync, cpSync, unlinkSync, readFileSync, readdirSync, renameSync, readlinkSync, rmdirSync, constants as fsConstants } from "fs";
11
+ import { mkdirSync, fstatSync, appendFileSync, existsSync, realpathSync, accessSync, cpSync, unlinkSync, readFileSync, readdirSync, renameSync, readlinkSync, rmdirSync, constants as fsConstants } from "fs";
12
12
  import { hostname, homedir, networkInterfaces } from "os";
13
13
  import { isIPv4 } from "net";
14
14
  import { join, basename, dirname, resolve } from "path";
@@ -1932,7 +1932,7 @@ async function callServe(
1932
1932
  throwOnFailure = false,
1933
1933
  upload?: UploadPayload,
1934
1934
  secret?: string,
1935
- ): Promise<{ status: number; stdout: string; stderr: string; files?: string[]; existingSession?: boolean }> {
1935
+ ): Promise<{ status: number; stdout: string; stderr: string; files?: string[]; existingSession?: boolean; secretOut?: string }> {
1936
1936
  const { key, host, port, protocol, extensionId, extensionToken, profileDirectory, userDataDir, loadExtension } = parseUrl(url);
1937
1937
  // Reuse the caller's identity when provided — computing it shells out to `git` several times,
1938
1938
  // and run() has already done so for its log line. Recomputing here would double those git
@@ -2169,6 +2169,29 @@ async function run(url: string, args: string[], overrideEnv?: Record<string, str
2169
2169
  let secret: string | undefined;
2170
2170
  let upload: UploadPayload | undefined;
2171
2171
  const cmdIdx = args.findIndex(a => !a.startsWith("-s="));
2172
+ if (args[cmdIdx] === "read-secret") {
2173
+ if (args.some(a => a === "--help" || a === "-h")) { console.log(READ_SECRET_USAGE); process.exit(0); }
2174
+ let wire: string[];
2175
+ try {
2176
+ // Only a pipe: a terminal would show the secret, and a file would keep it. Checked before
2177
+ // asking the host for it.
2178
+ const out = fstatSync(1);
2179
+ if (!out.isFIFO() && !out.isSocket()) throw new Error("read-secret writes the secret to stdout, which must be a pipe into the program that stores it (not a terminal or a file)");
2180
+ wire = readSecretWireArgs(parseReadSecretArgs(args.slice(cmdIdx)));
2181
+ } catch (err) {
2182
+ console.error(`[rech] ${err instanceof Error ? err.message : String(err)}\n${READ_SECRET_USAGE}`);
2183
+ process.exit(2);
2184
+ }
2185
+ const res = await callServe(url, [...args.filter(a => a.startsWith("-s=")), ...wire], overrideEnv, identity);
2186
+ if (res.status !== 0 || typeof res.secretOut !== "string") {
2187
+ process.stderr.write(res.stderr || (res.status === 0 ? "[rech] read-secret: this daemon is older than the client (no value returned)\n" : ""));
2188
+ process.exit(res.status || 1);
2189
+ }
2190
+ // Wait until the pipe has taken all of it before exiting.
2191
+ await new Promise<void>((done, fail) => process.stdout.write(res.secretOut!, e => e ? fail(e) : done()));
2192
+ console.error(`[rech] read-secret: wrote ${res.secretOut.length} characters to stdout`);
2193
+ process.exit(0);
2194
+ }
2172
2195
  if (args[cmdIdx] === "fill-secret") {
2173
2196
  if (args.some(a => a === "--help" || a === "-h")) { console.log(FILL_SECRET_USAGE); process.exit(0); }
2174
2197
  try {
@@ -3345,7 +3368,7 @@ async function rotateKey(name: string): Promise<void> {
3345
3368
  console.log(`New key for ${name}; URLs carrying the old key stop working now. Print new ones with: rech share <profile> --listener ${name}`);
3346
3369
  }
3347
3370
 
3348
- async function setListener(name: string, opts: { publicUrl?: string; clearPublicUrl?: boolean; uploads?: boolean; hostUploadDirs?: string[]; noHostUploads?: boolean }): Promise<void> {
3371
+ async function setListener(name: string, opts: { publicUrl?: string; clearPublicUrl?: boolean; uploads?: boolean; hostUploadDirs?: string[]; noHostUploads?: boolean; readSecrets?: boolean }): Promise<void> {
3349
3372
  const config = await requireListeners();
3350
3373
  let listener = config.listeners.find(l => l.name === name);
3351
3374
  if (!listener) throw new Error(`Unknown listener "${name}". See rech listener ls.`);
@@ -3363,7 +3386,12 @@ async function setListener(name: string, opts: { publicUrl?: string; clearPublic
3363
3386
  else policy.hostDirs = [...new Set([...(policy.hostDirs ?? []), ...opts.hostUploadDirs!.map(d => realpathSync(resolve(d)))])];
3364
3387
  listener.uploads = policy;
3365
3388
  }
3389
+ if (opts.readSecrets !== undefined) {
3390
+ if (listener.profiles === "*") throw new Error(`"${name}" is the local management listener: read-secret is always available there.`);
3391
+ if (opts.readSecrets) listener.readSecrets = true; else delete listener.readSecrets;
3392
+ }
3366
3393
  await writeListeners(config);
3394
+ if (opts.readSecrets !== undefined) console.log(opts.readSecrets ? `${name}: read-secret on. Anyone with this link can copy the value of any field (saved passwords included) on any site its profiles have open; --allow-domain only checks the site the caller names. Each read is logged without the value` : `${name}: read-secret off`);
3367
3395
  if (opts.publicUrl !== undefined || opts.clearPublicUrl) console.log(listener.publicUrl ? `${name} is reachable at ${listener.publicUrl}` : `${name}: public URL cleared`);
3368
3396
  if (opts.hostUploadDirs?.length || opts.noHostUploads) {
3369
3397
  const dirs = (listener.uploads || {}).hostDirs;
@@ -4447,7 +4475,7 @@ export type RechHandlers = {
4447
4475
  allowListener(name: string, profiles: string[]): Promise<void>;
4448
4476
  denyListener(name: string, profiles: string[]): Promise<void>;
4449
4477
  rotateKey(name: string): Promise<void>;
4450
- setListener(name: string, opts: { publicUrl?: string; clearPublicUrl?: boolean; uploads?: boolean; hostUploadDirs?: string[]; noHostUploads?: boolean }): Promise<void>;
4478
+ setListener(name: string, opts: { publicUrl?: string; clearPublicUrl?: boolean; uploads?: boolean; hostUploadDirs?: string[]; noHostUploads?: boolean; readSecrets?: boolean }): Promise<void>;
4451
4479
  setup(opts: SetupOptions): Promise<void>;
4452
4480
  tray(action?: string): Promise<void>;
4453
4481
  provisionProfile(name: string, opts: { headed: boolean; experimental: boolean }): Promise<void>;
@@ -4480,6 +4508,8 @@ const HELP_EPILOGUE = `Browser commands (sent to this project's Chrome session):
4480
4508
  --isolate in a throwaway session, e.g. for a login flow
4481
4509
  rech fill-secret <ref> --from-env VAR | --totp-from-env VAR [--env-file f] [--allow-domain '*.example.com']
4482
4510
  type a password / TOTP code without it reaching argv, logs or output
4511
+ rech read-secret <ref> --allow-domain <host> | <vault command>
4512
+ copy a field's value (e.g. an API secret) into a pipe, never shown or logged
4483
4513
  rech pw <args> forward verbatim to playwright-cli, e.g. \`rech pw --version\`
4484
4514
  rech --version rechrome's version
4485
4515
 
@@ -4595,9 +4625,10 @@ export function rechCli(argv: string[], handlers: RechHandlers) {
4595
4625
  .option("clear-public-url", { type: "boolean", conflicts: "public-url" })
4596
4626
  .option("uploads", { type: "boolean", describe: "Uploads of images the link holder sends (rech upload) are on by default; --no-uploads turns them off" })
4597
4627
  .option("host-upload-dir", { type: "string", array: true, requiresArg: true, describe: "Off by default. Also let links upload files already on this host, from inside this directory (rech upload --host <path>); repeatable" })
4628
+ .option("read-secrets", { type: "boolean", describe: "Off by default. Let this listener's links copy any field's value (saved passwords too) into a pipe (rech read-secret): only for links you trust with those accounts. --no-read-secrets turns it off" })
4598
4629
  .option("host-uploads", { type: "boolean", describe: "--no-host-uploads turns host-path uploads off again" })
4599
- .check(a => a.publicUrl !== undefined || a.clearPublicUrl || a.uploads !== undefined || a.hostUploadDir?.length || a.hostUploads === false ? true : "Pass --public-url <url>, --clear-public-url, --uploads/--no-uploads, or --host-upload-dir/--no-host-uploads"),
4600
- a => handlers.setListener(a.name, { publicUrl: a.publicUrl, clearPublicUrl: a.clearPublicUrl, ...(a.uploads !== undefined ? { uploads: a.uploads } : {}), ...(a.hostUploadDir?.length ? { hostUploadDirs: a.hostUploadDir as string[] } : {}), ...(a.hostUploads === false ? { noHostUploads: true } : {}) }))
4630
+ .check(a => a.publicUrl !== undefined || a.clearPublicUrl || a.uploads !== undefined || a.hostUploadDir?.length || a.hostUploads === false || a.readSecrets !== undefined ? true : "Pass --public-url <url>, --clear-public-url, --uploads/--no-uploads, or --host-upload-dir/--no-host-uploads"),
4631
+ a => handlers.setListener(a.name, { publicUrl: a.publicUrl, clearPublicUrl: a.clearPublicUrl, ...(a.uploads !== undefined ? { uploads: a.uploads } : {}), ...(a.hostUploadDir?.length ? { hostUploadDirs: a.hostUploadDir as string[] } : {}), ...(a.hostUploads === false ? { noHostUploads: true } : {}), ...(a.readSecrets !== undefined ? { readSecrets: a.readSecrets } : {}) }))
4601
4632
  .command("port [name]", "Print a listener's port (for a proxy command)", y => y.positional("name", { type: "string" }),
4602
4633
  a => handlers.listenerPort(a.name))
4603
4634
  .command("rotate-key <name>", "Give a listener a new key (old URLs stop working)", y => y.positional("name", { type: "string", demandOption: true }),
package/serve.js CHANGED
@@ -24,7 +24,7 @@ import {
24
24
  checkTailscaleServe,
25
25
  chromeDataAccessHint,
26
26
  } from "./rechrome.js";
27
- import { SecretMasker, parseFillSecretWire, fillSecretOnSession, passwordValuesOnSession, hasSnapshot, maskPasswordLines, withholdSnapshots } from "./fill-secret.js";
27
+ import { SecretMasker, parseReadSecretWire, readSecretOnSession, parseFillSecretWire, fillSecretOnSession, passwordValuesOnSession, hasSnapshot, maskPasswordLines, withholdSnapshots } from "./fill-secret.js";
28
28
 
29
29
  const TAILSCALE_BIN = process.env.TAILSCALE_BIN || "/Applications/Tailscale.app/Contents/MacOS/Tailscale";
30
30
  const CERT_RENEW_THRESHOLD_DAYS = 7;
@@ -944,6 +944,23 @@ export async function serve() {
944
944
  }
945
945
  }
946
946
 
947
+ // read-secret: the value goes back only in `secretOut`, never into stdout, a log line or a
948
+ // file, and is masked in every later output. See fill-secret.js.
949
+ if (filteredArgs[0] === "read-secret") {
950
+ try {
951
+ const { ref, allowDomains } = parseReadSecretWire(filteredArgs);
952
+ const { host, value } = await readSecretOnSession({ socketRoot: tmpSocketRoot(), session: namespacedSession, cwd: runWorkDir, ref, allowDomains });
953
+ if (!value) throw new Error(`read-secret: ${ref} on ${host} is empty`);
954
+ secretMasker.add(value, Infinity);
955
+ log(`exit: 0 | read-secret ${ref} on ${host} (${value.length} chars, value not logged)`);
956
+ return Response.json({ status: 0, stdout: "", stderr: "", files: [], secretOut: value });
957
+ } catch (error) {
958
+ const message = secretMasker.mask(error instanceof Error ? error.message : String(error));
959
+ log(`exit: 1 | read-secret: ${message.split("\n")[0]}`);
960
+ return Response.json({ status: 1, stdout: "", stderr: `[rech] ${message}\n`, files: [] });
961
+ }
962
+ }
963
+
947
964
  // For open commands, default to about:blank to avoid leaving connect.html visible
948
965
  const isOpenCmd = filteredArgs[0] === "open";
949
966
  const isOpenNoUrl = isOpenCmd && filteredArgs.length === 1;
package/serve.ts CHANGED
@@ -24,7 +24,7 @@ import {
24
24
  checkTailscaleServe,
25
25
  chromeDataAccessHint,
26
26
  } from "./rechrome.ts";
27
- import { SecretMasker, parseFillSecretWire, fillSecretOnSession, passwordValuesOnSession, hasSnapshot, maskPasswordLines, withholdSnapshots } from "./fill-secret.ts";
27
+ import { SecretMasker, parseReadSecretWire, readSecretOnSession, parseFillSecretWire, fillSecretOnSession, passwordValuesOnSession, hasSnapshot, maskPasswordLines, withholdSnapshots } from "./fill-secret.ts";
28
28
 
29
29
  const TAILSCALE_BIN = process.env.TAILSCALE_BIN || "/Applications/Tailscale.app/Contents/MacOS/Tailscale";
30
30
  const CERT_RENEW_THRESHOLD_DAYS = 7;
@@ -944,6 +944,23 @@ export async function serve() {
944
944
  }
945
945
  }
946
946
 
947
+ // read-secret: the value goes back only in `secretOut`, never into stdout, a log line or a
948
+ // file, and is masked in every later output. See fill-secret.ts.
949
+ if (filteredArgs[0] === "read-secret") {
950
+ try {
951
+ const { ref, allowDomains } = parseReadSecretWire(filteredArgs);
952
+ const { host, value } = await readSecretOnSession({ socketRoot: tmpSocketRoot(), session: namespacedSession, cwd: runWorkDir, ref, allowDomains });
953
+ if (!value) throw new Error(`read-secret: ${ref} on ${host} is empty`);
954
+ secretMasker.add(value, Infinity);
955
+ log(`exit: 0 | read-secret ${ref} on ${host} (${value.length} chars, value not logged)`);
956
+ return Response.json({ status: 0, stdout: "", stderr: "", files: [], secretOut: value });
957
+ } catch (error) {
958
+ const message = secretMasker.mask(error instanceof Error ? error.message : String(error));
959
+ log(`exit: 1 | read-secret: ${message.split("\n")[0]}`);
960
+ return Response.json({ status: 1, stdout: "", stderr: `[rech] ${message}\n`, files: [] });
961
+ }
962
+ }
963
+
947
964
  // For open commands, default to about:blank to avoid leaving connect.html visible
948
965
  const isOpenCmd = filteredArgs[0] === "open";
949
966
  const isOpenNoUrl = isOpenCmd && filteredArgs.length === 1;