Files
ARTEX/server/env_scrub_test.go
BaaRai e6f4de5ddc fix(security): scrub startup secrets before any child can spawn
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.
2026-11-03 22:14:35 +01:00

37 lines
813 B
Go

package server
import (
"os/exec"
"strings"
"testing"
)
// A child process spawned after startup must not see the startup secrets, while
// other variables still pass through.
func TestScrubSecretEnvHidesSecretsFromChildren(t *testing.T) {
sh, err := exec.LookPath("sh")
if err != nil {
t.Skip("no sh in PATH")
}
for _, k := range secretEnv {
t.Setenv(k, "leak-"+k)
}
t.Setenv("ARTEX_SCRUB_KEEP", "kept")
ScrubSecretEnv()
out, err := exec.Command(sh, "-c", "env").Output()
if err != nil {
t.Fatal(err)
}
env := "\n" + string(out)
for _, k := range secretEnv {
if strings.Contains(env, "\n"+k+"=") {
t.Errorf("%s still reaches child processes", k)
}
}
if !strings.Contains(env, "\nARTEX_SCRUB_KEEP=kept\n") {
t.Errorf("non-secret variable did not reach the child process")
}
}