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(security): filter env vars in PTY shell sessions to prevent secret leakage
Adam Eivyb23c005f0127
diff --git a/.changelog/v0.16.x.md b/.changelog/v0.16.x.mdindex ef7bcf93b1..bb13b88352 100644--- a/.changelog/v0.16.x.md+++ b/.changelog/v0.16.x.md@@ -6,6 +6,13 @@ Released: YYYY-MM-DDAgent persistence, reliability, and decision transparency improvements.+## Security++### PTY shell sessions no longer leak environment secrets+- **Previously**, `pty.spawn()` spread the entire `process.env` into shell sessions, exposing API keys, tokens, and other secrets to anyone running `env` in the terminal+- **Now uses an explicit allowlist** of safe environment variable prefixes (`PATH`, `HOME`, `SHELL`, toolchain vars like `NVM_`, `GOPATH`, etc.) so only standard/non-sensitive variables are passed through+- Secrets like `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, and any other `*_KEY`/`*_TOKEN`/`*_SECRET` vars are no longer accessible from spawned shells+## Fixes### Agent history now persists across state resetsdiff --git a/server/services/shell.js b/server/services/shell.jsindex fa660d0cf9..1a4395c447 100644--- a/server/services/shell.js+++ b/server/services/shell.js@@ -5,6 +5,27 @@ import { v4 as uuidv4 } from 'uuid';// Store active shell sessionsconst shellSessions = new Map();+// Allowlist of safe environment variable prefixes to pass to PTY sessions+// Prevents leaking secrets (API keys, tokens) to the shell+const SAFE_ENV_PREFIXES = [+ 'HOME', 'USER', 'LOGNAME', 'SHELL', 'PATH', 'LANG', 'LC_', 'TERM',+ 'COLORTERM', 'EDITOR', 'VISUAL', 'HOSTNAME', 'PWD', 'OLDPWD', 'TMPDIR',+ 'XDG_', 'SSH_AUTH_SOCK', 'DISPLAY', 'HOMEBREW_', 'NVM_', 'FNM_', 'NODE_',+ 'NPM_', 'VOLTA_', 'GOPATH', 'GOROOT', 'CARGO_', 'RUSTUP_', 'PYENV_',+ 'VIRTUAL_ENV', 'CONDA_', 'JAVA_HOME', 'ANDROID_', 'DOCKER_', 'COMPOSE_',+ 'KUBECONFIG', 'LESS', 'PAGER', 'MANPATH', 'INFOPATH', 'ZDOTDIR', 'STARSHIP_'+];++function buildSafeEnv() {+ const safeEnv = {};+ for (const [key, value] of Object.entries(process.env)) {+ if (SAFE_ENV_PREFIXES.some(prefix => key === prefix || key.startsWith(prefix))) {+ safeEnv[key] = value;+ }+ }+ return safeEnv;+}+/*** Get the default shell for the current OS*/@@ -35,7 +56,7 @@ export function createShellSession(socket, options = {}) {rows,cwd,env: {- ...process.env,+ ...buildSafeEnv(),TERM: 'xterm-256color',COLORTERM: 'truecolor'}