Repository navigation
Conversation
…s spawn shells ARTEX_PG_DSN, ANTHROPIC_API_KEY and OPENAI_API_KEY are read once at startup (server.NewManager, agent.FromEnv in server.New) and never again. They stayed in the process environment, and every subprocess copies os.Environ() when it is spawned: the agent Bash shell and background tasks (norma tool.withEnv), MCP stdio servers and custom tools (server/customtool.go). An agent could print the database password or the LLM key with `env`. Unset them in main right after server.New returns. Adds a test that a shell spawned afterwards no longer sees them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ARTEX_PG_DSN(it holds the Postgres password),ANTHROPIC_API_KEYandOPENAI_API_KEYstay in the server's process environment for the whole run. Every subprocess copiesos.Environ()when it is spawned:tool.withEnv(tool/task.go, in the BaaRai/Norma v0.4.4 fork)mcp/stdio.goserver/customtool.go:400,c.Env = append(os.Environ(), sessionEnv...)So an agent, or a prompt injection steering it, can read the database password or the LLM key with
env.Fix
These three variables are read only at startup:
ARTEX_PG_DSN:config.PostgresDSNviadb.DSN, called only fromserver.NewManager(all other callers are tests)agent.FromEnv, called only fromserver.Newmainnow unsets them right afterserver.Newreturns (scrubSecretEnv). All the spawn paths above read the environment when the process starts, so this one change covers them. Nothing needs to change in the norma fork or incustomtool.go.Nothing in ARTEX relies on norma's
llm.NewProviderfalling back toANTHROPIC_API_KEY/OPENAI_API_KEYlater. Every profile path rejects an empty key or reuses the key held in memory (s.llmCfg.APIKey) before it builds a provider. A restart still works:start.shrelaunchesartexwith its own unchanged environment.Limits (not fixed here)
/proc/<pid>/environ:os.Unsetenvchanges the Go runtime's copy of the environment, not the block the kernel recorded at exec. A shell running as the same user can still read/proc/<artex pid>/environ. In Docker it can also read/proc/1/environfromstart.sh, which is PID 1 and keeps the full environment. Closing that path means running agent shells as another user, or not passing the secrets through the environment (for example a mounted secrets file). Both are out of scope for this PR.server.Newstarts some goroutines before it returns. The one that matters isdiscoverEmptyMCPsOnStartup, which on a first run can spawn an MCP server before the scrub. That discovery process is short-lived. Agent shells start only after an LLM round trip, so they are spawned after the scrub.ARTEX_LLM_PROXYcan carry proxy credentials and is not scrubbed. It is not in the scope of this change.Verification
Run in WSL (kali), Go 1.26.7, against a throwaway
postgres:16-alpinecontainer on port 55432 (removed afterwards):go build -buildvcs=false ./...: OK.-buildvcs=falseonly because the worktree's git dir is a Windows path.go vet ./...: OKgofmt: the changed files are cleango test ./server ./agent ./cmd/artex ./config ./db -count=1: all pass exceptTestCoreTaskLifecyclePGin./server. That test is known to fail in this environment for timing reasons, and it fails the same way on the PR2 branch. There is no./toolpackage in this repo; the shell code lives in norma.TestScrubSecretEnvHidesCredentialsFromSubprocesses(cmd/artex): sets the three variables, callsscrubSecretEnv, spawnssh -c env, and asserts that none of them reaches the child while a non-secret variable still does. Passes.Not verified: a real
docker composebuild and run, and an end-to-end agent shell session. I did not touch the live stack.🤖 Generated with Claude Code