Repository navigation
fix(security): remove startup secrets from the environment before child processes spawn - #136
Merged
Merged
Conversation
…ld processes spawn ARTEX_PG_DSN, ANTHROPIC_API_KEY and OPENAI_API_KEY are read only during startup (server.NewManager and agent.FromEnv in server.New), but stayed in the process environment. Agent shells, custom tools and MCP stdio servers copy os.Environ() when they start, so they could read the database password and the LLM keys. main now unsets the three variables right after server.New returns.
The scrub ran in main after server.New returned, but New resumes every non-terminal task before returning, and those loops start workers that run shells. Move the scrub into New, right after both environment readers, and start MCP discovery after it as well: both paths spawn child processes. New takes an option rather than scrubbing unconditionally. The test suite builds several servers in one process and still needs ARTEX_PG_DSN on later calls, so only the binary opts in.
BaaRai
force-pushed
the
fix/shell-env-secrets
branch
from
November 3, 2026 21:14
428a1b2 to
e6f4de5
Compare
neartana
pushed a commit
to neartana/ARTEX
that referenced
this pull request
Nov 3, 2026
New accepted opts ...Option but never called them, so scrubSecrets stayed false in the binary and ScrubSecretEnv was unreachable: the protection merged in BaaRai#136 never engaged. The unit test passed because it called the scrub function directly instead of going through New. Apply the options in the constructor and add a test that builds a Server through New with WithSecretScrub and asserts the secrets are gone. Verified to fail without the loop.
Merged
BaaRai
added a commit
that referenced
this pull request
Nov 4, 2026
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 contains the Postgres password),ANTHROPIC_API_KEYandOPENAI_API_KEYstay in the server's process environment for the whole run. Child processes copyos.Environ()when they are spawned:tool/bash.go,tool/task.go,tool/shell_session.go(BaaRai/Norma v0.4.4, thereplacetarget ingo.mod)mcp/stdio.goserver/customtool.go:400So an agent, or a prompt injection steering it, can print the database password or the LLM key with
env.Fix
The three variables are read only at startup:
ARTEX_PG_DSN:config.PostgresDSNthroughdb.DSN, called only fromserver.NewManager(server/manager.go:379); the other callers are testsagent.FromEnv(agent/provider.go:207), called only fromserver.New(server/server.go:247)mainnow callsscrubSecretEnv()right afterserver.Newreturns, which unsets the three variables. All the spawn paths above read the environment when the child starts, so this one change incmd/artexcovers them; nothing changes in norma or incustomtool.go.Later provider builds do not depend on these variables: the profile paths reject an empty key (
loadProfileConfig) or reuse the key already in memory (s.llmCfg.APIKey) before callingNewProvider, so norma'sllm.NewProviderenv fallback is never reached with an empty key.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 process running as the same user can still read/proc/<artex pid>/environ(and, in Docker, the environment of PID 1). So this does not fully protect the secrets. Closing that path needs agent shells running as another user, or secrets passed some other way than the environment (for example a mounted file).server.Newstarts a few goroutines before it returns. On a first run,discoverEmptyMCPsOnStartupcan spawn an MCP stdio server for tool discovery before the scrub runs. That process is short-lived.ARTEX_LLM_PROXY) are not touched.Verification
WSL (kali), Go 1.26.7, throwaway
postgres:16-alpineon port 55432 (removed afterwards):go build -buildvcs=false ./...: OK (-buildvcs=falseonly because the worktree's git dir is a Windows path)go vet -buildvcs=false ./...: OKgofmt -lon the changed files: cleango test ./server ./agent ./cmd/artex ./config ./db -count=1:agent,cmd/artex,config,dbpass.serverfails only onTestCoreTaskLifecyclePG, which is known to fail in this environment on timing and is unrelated to this change.TestScrubSecretEnvHidesSecretsFromChildren(cmd/artex): sets the three variables plus a normal one, callsscrubSecretEnv, runssh -c env, and checks that none of the three reaches the child while the normal variable does. It fails whenscrubSecretEnvis turned into a no-op and passes with it.Not verified: a Docker build and run, and an end-to-end agent shell session.