Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: address review (claude r2) — scan provider-injected + non-key-named env secrets in diff gate (#2371)
Adam Eivy55b7e599134d
diff --git a/autofixer/sandbox.js b/autofixer/sandbox.jsindex 9394154ebc..557df5c88b 100644--- a/autofixer/sandbox.js+++ b/autofixer/sandbox.js@@ -99,6 +99,34 @@ export function sanitizeChildEnv(baseEnv = process.env) {return out;}+/**+ * Collect the credential VALUES the agent's environment exposes, for the diff+ * secret-scan (scanDiffForSecrets) — so an agent that reads a key at runtime+ * (e.g. `/proc/self/environ`, which stays readable even with Bash denied) can't+ * write it into a source file and promote it. Scoped to auth-bearing keys ++ * everything the runner injects via `provider.envVars` (Bedrock/Vertex/custom+ * keys delivered only there), and deliberately excludes system vars (PATH/HOME)+ * so a diff legitimately referencing a path isn't a false positive.+ *+ * @param {Record<string,string>} childEnv the sanitized child env+ * @param {Record<string,string>} [providerEnvVars] provider.envVars overlaid by the runner+ * @returns {string[]}+ */+export function collectSecretEnvValues(childEnv = {}, providerEnvVars = {}) {+ const vals = [];+ for (const [k, v] of Object.entries(childEnv || {})) {+ if (+ PROVIDER_AUTH_ALLOW.has(k) ||+ PROVIDER_AUTH_PREFIXES.some((p) => k.startsWith(p)) ||+ /API_KEY|TOKEN|SECRET|CREDENTIAL|_KEY$/i.test(k)+ ) {+ vals.push(v);+ }+ }+ for (const v of Object.values(providerEnvVars || {})) vals.push(v);+ return vals.filter((v) => typeof v === 'string' && v.length >= 8);+}+// ---------------------------------------------------------------------------// Prompt construction (untrusted-log fencing)// ---------------------------------------------------------------------------diff --git a/autofixer/sandbox.test.js b/autofixer/sandbox.test.jsindex e48074907a..83e0bb75c0 100644--- a/autofixer/sandbox.test.js+++ b/autofixer/sandbox.test.js@@ -1,6 +1,7 @@import { describe, it, expect } from 'vitest';import {sanitizeChildEnv,+ collectSecretEnvValues,buildFixPrompt,defuseSentinel,restrictedToolArgs,@@ -69,6 +70,30 @@ describe('sanitizeChildEnv — credential stripping', () => {});});+describe('collectSecretEnvValues — exfil-scan value list', () => {+ it('includes auth-key values and provider.envVars, excludes system paths', () => {+ const childEnv = {+ PATH: '/usr/local/bin:/usr/bin',+ HOME: '/home/someuser',+ ANTHROPIC_API_KEY: 'sk-ant-childkeyvalue123',+ OPENCODE_CONFIG_CONTENT: 'config-with-embedded-secret-abc',+ };+ // Bedrock/custom key delivered ONLY via provider.envVars (overlaid by runner).+ const providerEnvVars = { AWS_BEARER_TOKEN_BEDROCK: 'bedrock-opaque-token-xyz' };+ const values = collectSecretEnvValues(childEnv, providerEnvVars);+ expect(values).toContain('sk-ant-childkeyvalue123');+ expect(values).toContain('config-with-embedded-secret-abc'); // non-key-named allowlisted var+ expect(values).toContain('bedrock-opaque-token-xyz'); // provider-injected+ // System paths are NOT scanned (would false-positive on legit path edits).+ expect(values).not.toContain('/usr/local/bin:/usr/bin');+ expect(values).not.toContain('/home/someuser');+ });++ it('drops short values to avoid false positives', () => {+ expect(collectSecretEnvValues({ API_KEY: 'short' })).toEqual([]);+ });+});+describe('buildFixPrompt — untrusted log fencing', () => {const app = { name: 'DemoApp', id: 'demo' };diff --git a/autofixer/server.js b/autofixer/server.jsindex a278f56d54..5fce32ed5a 100644--- a/autofixer/server.js+++ b/autofixer/server.js@@ -11,6 +11,7 @@ import { pickCliProvider, runCliProviderPrompt } from '../server/lib/cliProviderimport { agentGuardEnv } from '../server/lib/agentGuard/index.js';import {sanitizeChildEnv,+ collectSecretEnvValues,buildFixPrompt,restrictedToolArgs,validateProposedDiff,@@ -342,11 +343,10 @@ async function fixProcess(processName, app, errorLogs, outputLogs) {// work from an agent that didn't finish cleanly.const diff = await collectWorktreeDiff(worktreePath);const agentOk = !result.error;- // The live env's provider-auth values — reject any diff that tries to write- // one into the repo (agent read-then-promote exfil backstop).- const secretValues = Object.entries(childEnv)- .filter(([k]) => /API_KEY|TOKEN|SECRET|CREDENTIAL/i.test(k))- .map(([, v]) => v);+ // The live env's provider-auth values (incl. runner-injected provider.envVars+ // keys) — reject any diff that tries to write one into the repo (agent+ // read-then-promote exfil backstop).+ const secretValues = collectSecretEnvValues(childEnv, picked.provider?.envVars);const validation = agentOk? validateProposedDiff(diff, { maxBytes: MAX_DIFF_BYTES, secretValues }): { ok: false, reason: `agent did not complete: ${result.error}`, files: [] };