@steerable/agent-shell 0.14.0 → 0.14.2

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.
@@ -2,12 +2,20 @@ import type { CredentialInjection, PackCredentialClient, PackDataSource, Princip
2
2
  import type { ScopedStore } from '../storage/scoped-store.js';
3
3
  export declare const REDACTED_CREDENTIAL_MARKER = "[REDACTED:credential]";
4
4
  export declare const TENANT_CREDENTIAL_OWNER = "__tenant__";
5
+ /**
6
+ * Registers a host-level secret so every `SecretRedactor` instance created
7
+ * afterward scrubs its raw, URL-encoded, and Base64-encoded forms.
8
+ */
9
+ export declare function registerGlobalSecret(secret: string): () => void;
10
+ /** Clears process-wide registered secrets in unit tests. */
11
+ export declare function clearGlobalSecretsForTests(): void;
5
12
  /**
6
13
  * Tracks active plaintext secrets and scrubs their raw, URL-encoded, and
7
14
  * base64-encoded forms from strings and structured JSON payloads.
8
15
  */
9
16
  export declare class SecretRedactor {
10
17
  private readonly needles;
18
+ constructor();
11
19
  /** Registers one or more secret strings for scrubbing. */
12
20
  registerSecret(secret: string): void;
13
21
  /** Registers every string leaf inside a CredentialInjection payload. */
@@ -27,12 +27,35 @@ export const TENANT_CREDENTIAL_OWNER = '__tenant__';
27
27
  const MIN_REDACT_SECRET_LEN = 4;
28
28
  const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
29
29
  const MAX_CREDENTIAL_REDIRECTS = 5;
30
+ const globalSecretNeedles = new Set();
31
+ /**
32
+ * Registers a host-level secret so every `SecretRedactor` instance created
33
+ * afterward scrubs its raw, URL-encoded, and Base64-encoded forms.
34
+ */
35
+ export function registerGlobalSecret(secret) {
36
+ const trimmed = secret.trim();
37
+ if (trimmed.length < MIN_REDACT_SECRET_LEN)
38
+ return () => { };
39
+ globalSecretNeedles.add(trimmed);
40
+ return () => {
41
+ globalSecretNeedles.delete(trimmed);
42
+ };
43
+ }
44
+ /** Clears process-wide registered secrets in unit tests. */
45
+ export function clearGlobalSecretsForTests() {
46
+ globalSecretNeedles.clear();
47
+ }
30
48
  /**
31
49
  * Tracks active plaintext secrets and scrubs their raw, URL-encoded, and
32
50
  * base64-encoded forms from strings and structured JSON payloads.
33
51
  */
34
52
  export class SecretRedactor {
35
53
  needles = new Set();
54
+ constructor() {
55
+ for (const secret of globalSecretNeedles) {
56
+ this.registerSecret(secret);
57
+ }
58
+ }
36
59
  /** Registers one or more secret strings for scrubbing. */
37
60
  registerSecret(secret) {
38
61
  const trimmed = secret.trim();
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Registers additional exact environment variable names or `PREFIX_` patterns
3
+ * to strip from tool-spawned child processes.
4
+ *
5
+ * Entries ending with `_` match as case-insensitive prefixes; all other entries
6
+ * match exact variable names case-insensitively.
7
+ */
8
+ export declare function registerProtectedEnvKeys(entries: readonly string[]): () => void;
9
+ /** Clears custom protected env rules in unit tests. */
10
+ export declare function resetProtectedEnvKeysForTests(): void;
11
+ /** True when `key` is a host-protected secret variable that tools must not inherit. */
12
+ export declare function isProtectedHostEnvKey(key: string): boolean;
13
+ /**
14
+ * Builds a clean child-process environment from `sourceEnv`, stripping
15
+ * host-protected keys (and registering their values into `SecretRedactor`),
16
+ * then applying caller-supplied `extraEnv`.
17
+ */
18
+ export declare function scrubToolSubprocessEnv(sourceEnv?: NodeJS.ProcessEnv, extraEnv?: Record<string, string>): Record<string, string>;
19
+ /** Scrubs any registered global/host secrets from subprocess text output. */
20
+ export declare function redactSubprocessText(text: string): string;
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Product-neutral environment sanitizer for tool-spawned child processes
3
+ * (`local_exec_shell`, `local_run_snippet`, and interactive PTY sessions).
4
+ *
5
+ * Host master keys, internal RPC tokens, shared database URLs, and host-managed
6
+ * model provider API keys are stripped from ambient `process.env` before a tool
7
+ * subprocess starts, while explicit per-call `extraEnv` (such as `custom_env`
8
+ * injections authorized through `CredentialBroker`) is preserved.
9
+ */
10
+ import { SecretRedactor, registerGlobalSecret } from './auth/credentials.js';
11
+ const DEFAULT_PROTECTED_EXACT_KEYS = new Set([
12
+ 'STEERABLE_CREDENTIAL_MASTER_KEY',
13
+ 'DEEPSEEK_API_KEY',
14
+ 'OPENAI_API_KEY',
15
+ 'OPENAI_COMPAT_API_KEY',
16
+ 'ANTHROPIC_API_KEY',
17
+ 'GEMINI_API_KEY',
18
+ 'GOOGLE_API_KEY',
19
+ 'DASHSCOPE_API_KEY',
20
+ ]);
21
+ const DEFAULT_PROTECTED_PREFIXES = [
22
+ 'STEERABLE_INTERNAL_',
23
+ ];
24
+ const DEFAULT_PROTECTED_SUFFIXES = [
25
+ '_INTERNAL_TOKEN',
26
+ '_INTERNAL_BEARER',
27
+ '_BOOTSTRAP_TOKEN',
28
+ '_MYSQL_URL',
29
+ '_DATABASE_URL',
30
+ '_POSTGRES_URL',
31
+ ];
32
+ const customExactKeys = new Set();
33
+ const customPrefixes = new Set();
34
+ /**
35
+ * Registers additional exact environment variable names or `PREFIX_` patterns
36
+ * to strip from tool-spawned child processes.
37
+ *
38
+ * Entries ending with `_` match as case-insensitive prefixes; all other entries
39
+ * match exact variable names case-insensitively.
40
+ */
41
+ export function registerProtectedEnvKeys(entries) {
42
+ const addedExact = [];
43
+ const addedPrefixes = [];
44
+ for (const raw of entries) {
45
+ const upper = raw.trim().toUpperCase();
46
+ if (!upper)
47
+ continue;
48
+ if (upper.endsWith('_')) {
49
+ if (!customPrefixes.has(upper)) {
50
+ customPrefixes.add(upper);
51
+ addedPrefixes.push(upper);
52
+ }
53
+ }
54
+ else if (!customExactKeys.has(upper)) {
55
+ customExactKeys.add(upper);
56
+ addedExact.push(upper);
57
+ }
58
+ }
59
+ return () => {
60
+ for (const k of addedExact)
61
+ customExactKeys.delete(k);
62
+ for (const p of addedPrefixes)
63
+ customPrefixes.delete(p);
64
+ };
65
+ }
66
+ /** Clears custom protected env rules in unit tests. */
67
+ export function resetProtectedEnvKeysForTests() {
68
+ customExactKeys.clear();
69
+ customPrefixes.clear();
70
+ }
71
+ /** True when `key` is a host-protected secret variable that tools must not inherit. */
72
+ export function isProtectedHostEnvKey(key) {
73
+ const upper = key.trim().toUpperCase();
74
+ if (!upper)
75
+ return false;
76
+ if (DEFAULT_PROTECTED_EXACT_KEYS.has(upper) || customExactKeys.has(upper)) {
77
+ return true;
78
+ }
79
+ for (const prefix of DEFAULT_PROTECTED_PREFIXES) {
80
+ if (upper.startsWith(prefix))
81
+ return true;
82
+ }
83
+ for (const prefix of customPrefixes) {
84
+ if (upper.startsWith(prefix))
85
+ return true;
86
+ }
87
+ for (const suffix of DEFAULT_PROTECTED_SUFFIXES) {
88
+ if (upper.endsWith(suffix))
89
+ return true;
90
+ }
91
+ return false;
92
+ }
93
+ function registerUrlPasswordIfPresent(raw) {
94
+ try {
95
+ const parsed = new URL(raw);
96
+ if (parsed.password) {
97
+ registerGlobalSecret(decodeURIComponent(parsed.password));
98
+ }
99
+ }
100
+ catch {
101
+ // Non-URL secret value; full string registration already covers it.
102
+ }
103
+ }
104
+ /**
105
+ * Builds a clean child-process environment from `sourceEnv`, stripping
106
+ * host-protected keys (and registering their values into `SecretRedactor`),
107
+ * then applying caller-supplied `extraEnv`.
108
+ */
109
+ export function scrubToolSubprocessEnv(sourceEnv = process.env, extraEnv) {
110
+ const clean = {};
111
+ for (const [key, value] of Object.entries(sourceEnv)) {
112
+ if (typeof value !== 'string')
113
+ continue;
114
+ if (isProtectedHostEnvKey(key)) {
115
+ if (value.trim().length > 0) {
116
+ registerGlobalSecret(value);
117
+ registerUrlPasswordIfPresent(value);
118
+ }
119
+ continue;
120
+ }
121
+ clean[key] = value;
122
+ }
123
+ if (extraEnv) {
124
+ for (const [key, value] of Object.entries(extraEnv)) {
125
+ if (typeof value === 'string') {
126
+ clean[key] = value;
127
+ }
128
+ }
129
+ }
130
+ return clean;
131
+ }
132
+ /** Scrubs any registered global/host secrets from subprocess text output. */
133
+ export function redactSubprocessText(text) {
134
+ if (!text)
135
+ return text;
136
+ const redactor = new SecretRedactor();
137
+ return redactor.hasSecrets ? redactor.redactString(text) : text;
138
+ }
@@ -11,6 +11,7 @@ import { adaptCommandForPowerShell } from './shell-adapt.js';
11
11
  import { evaluateExecPolicy, planSshArgv, } from './shell-exec.js';
12
12
  import { nodeShellBackend } from './shell-process.js';
13
13
  import { closeShellSession, readShellSession, shellSessionStatus, startPtySession, } from './shell-session.js';
14
+ import { redactSubprocessText, scrubToolSubprocessEnv } from './env-sanitizer.js';
14
15
  import { applyEdits, EditError } from './local-edit.js';
15
16
  // `he` ships as CommonJS and does not expose ESM named exports, so we have to
16
17
  // take the default import and destructure at runtime in this ESM module.
@@ -242,14 +243,7 @@ const BUILTIN_DANGEROUS = [
242
243
  { id: 'win_rd_force', pattern: '\\brd\\s+\\/s\\s+\\/q\\s+[a-z]:\\\\', platform: 'windows' },
243
244
  ];
244
245
  function stringEnv(extra) {
245
- const env = {};
246
- for (const [key, value] of Object.entries(process.env)) {
247
- if (typeof value === 'string')
248
- env[key] = value;
249
- }
250
- if (extra)
251
- Object.assign(env, extra);
252
- return env;
246
+ return scrubToolSubprocessEnv(process.env, extra);
253
247
  }
254
248
  function toWslPath(input) {
255
249
  const normalized = input.replace(/\\/g, '/');
@@ -418,7 +412,7 @@ export class LocalExecutor {
418
412
  }
419
413
  const timeout = Math.max(1000, rawTimeout);
420
414
  const cwd = this.resolveCwd(request.cwd, resolvedShell.type);
421
- const env = { ...process.env, ...(request.env || {}) };
415
+ const env = scrubToolSubprocessEnv(process.env, request.env);
422
416
  if (this.shellBackend || useSsh || request.pty) {
423
417
  return await this.runPlannedShell({
424
418
  command,
@@ -506,9 +500,9 @@ export class LocalExecutor {
506
500
  clearTimeout(timer);
507
501
  resolve({
508
502
  success: false,
509
- stdout: Buffer.concat(stdoutChunks).toString('utf-8'),
510
- stderr: Buffer.concat(stderrChunks).toString('utf-8'),
511
- error: err.message,
503
+ stdout: redactSubprocessText(Buffer.concat(stdoutChunks).toString('utf-8')),
504
+ stderr: redactSubprocessText(Buffer.concat(stderrChunks).toString('utf-8')),
505
+ error: redactSubprocessText(err.message),
512
506
  truncated,
513
507
  shell: resolvedShell.type,
514
508
  platform: process.platform,
@@ -518,8 +512,8 @@ export class LocalExecutor {
518
512
  clearTimeout(timer);
519
513
  resolve({
520
514
  success: exitCode === 0,
521
- stdout: Buffer.concat(stdoutChunks).toString('utf-8'),
522
- stderr: Buffer.concat(stderrChunks).toString('utf-8'),
515
+ stdout: redactSubprocessText(Buffer.concat(stdoutChunks).toString('utf-8')),
516
+ stderr: redactSubprocessText(Buffer.concat(stderrChunks).toString('utf-8')),
523
517
  exitCode: exitCode ?? -1,
524
518
  truncated,
525
519
  shell: resolvedShell.type,
@@ -4,24 +4,19 @@
4
4
  */
5
5
  import { randomUUID } from 'node:crypto';
6
6
  import * as pty from 'node-pty';
7
+ import { redactSubprocessText, scrubToolSubprocessEnv } from './env-sanitizer.js';
7
8
  import { stripAnsi } from './shell-process.js';
8
9
  const MAX_SESSION_MS = 10 * 60 * 1000;
9
10
  const QUIET_MS = 200;
10
11
  const MAX_YIELD_MS = 120_000;
11
12
  const sessions = new Map();
12
13
  function stringEnv(env) {
13
- const next = {};
14
- for (const [key, value] of Object.entries(process.env)) {
15
- if (typeof value === 'string')
16
- next[key] = value;
17
- }
18
- if (env)
19
- Object.assign(next, env);
14
+ const next = scrubToolSubprocessEnv(process.env, env);
20
15
  next.TERM = 'xterm-256color';
21
16
  return next;
22
17
  }
23
18
  function takeNew(live) {
24
- const fresh = stripAnsi(live.raw.slice(live.cursor));
19
+ const fresh = redactSubprocessText(stripAnsi(live.raw.slice(live.cursor)));
25
20
  live.cursor = live.raw.length;
26
21
  return fresh;
27
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steerable/agent-shell",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "description": "Steerable framework — product-neutral Node HostRuntime and headless HTTP server shared by Tauri desktop and browser deployments; scenario packs extend it through @steerable/pack-sdk.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://steerableframework.com/",
@@ -53,10 +53,10 @@
53
53
  "jpeg-js": "^0.4.4",
54
54
  "node-pty": "^1.1.0",
55
55
  "pngjs": "^7.0.0",
56
- "@steerable/agent-harness": "0.14.0",
57
- "@steerable/agent-protocol": "0.14.0",
58
- "@steerable/agent-runtime": "0.14.0",
59
- "@steerable/pack-sdk": "0.14.0"
56
+ "@steerable/agent-harness": "0.14.2",
57
+ "@steerable/agent-runtime": "0.14.2",
58
+ "@steerable/pack-sdk": "0.14.2",
59
+ "@steerable/agent-protocol": "0.14.2"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/better-sqlite3": "^7.6.13",