mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-25 09:20:53 +08:00
server: keep only the fixed locale names in the executor environment
The executor environment kept every name starting with LC_, so a secret supplied under an LC_ name crossed the allowlist even though the comment promised a fixed set of names. The POSIX locale categories are now enumerated and the prefix rule is gone. Found by jamesKhor in the review of #478.
This commit is contained in:
+6
-12
@@ -28,6 +28,9 @@ import (
|
||||
var executorEnvNames = nameSet(
|
||||
"PATH", "HOME", "XDG_CACHE_HOME",
|
||||
"LANG", "LANGUAGE", "TERM", "TZ", "TMPDIR",
|
||||
"LC_ALL", "LC_CTYPE", "LC_NUMERIC", "LC_TIME", "LC_COLLATE", "LC_MONETARY",
|
||||
"LC_MESSAGES", "LC_PAPER", "LC_NAME", "LC_ADDRESS", "LC_TELEPHONE",
|
||||
"LC_MEASUREMENT", "LC_IDENTIFICATION",
|
||||
"PAGER", "GIT_PAGER", "SYSTEMD_PAGER", "DEBIAN_FRONTEND",
|
||||
"HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy",
|
||||
"ALL_PROXY", "all_proxy", "NO_PROXY", "no_proxy", "NODE_USE_ENV_PROXY",
|
||||
@@ -44,25 +47,16 @@ func nameSet(names ...string) map[string]bool {
|
||||
return m
|
||||
}
|
||||
|
||||
// executorEnvPrefixes are kept by prefix: the locale categories.
|
||||
var executorEnvPrefixes = []string{"LC_"}
|
||||
|
||||
// envExecKeep lists, comma-separated, names the drop shim keeps besides the
|
||||
// allowlist: the variables an MCP stdio server is given in its configuration. It is
|
||||
// not kept itself.
|
||||
const envExecKeep = "ARTEX_EXEC_KEEP"
|
||||
|
||||
// executorEnvAllowed reports whether the variable name crosses to an agent process.
|
||||
// The locale categories are the fixed POSIX set: a variable whose name starts with
|
||||
// LC_ is not kept by prefix, so a secret cannot cross under an LC_ name.
|
||||
func executorEnvAllowed(name string) bool {
|
||||
if executorEnvNames[name] {
|
||||
return true
|
||||
}
|
||||
for _, p := range executorEnvPrefixes {
|
||||
if strings.HasPrefix(name, p) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return executorEnvNames[name]
|
||||
}
|
||||
|
||||
// executorEnv returns the entries of env an agent process keeps: the allowlisted
|
||||
|
||||
@@ -8,19 +8,19 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// The allowlist keeps the named and prefixed variables and the extra names, and
|
||||
// drops everything else, secrets under known and unknown names alike.
|
||||
// The allowlist keeps the named variables and the extra names, and drops
|
||||
// everything else, secrets under known and unknown names alike.
|
||||
func TestExecutorEnvAllowlist(t *testing.T) {
|
||||
env := []string{
|
||||
"PATH=/usr/bin", "LANG=C.UTF-8", "LC_ALL=C", "HTTP_PROXY=http://127.0.0.1:8788",
|
||||
"PATH=/usr/bin", "LANG=C.UTF-8", "LC_ALL=C", "LC_CTYPE=C.UTF-8", "HTTP_PROXY=http://127.0.0.1:8788",
|
||||
"SSL_CERT_FILE=/ca.pem", "PLAYWRIGHT_BROWSERS_PATH=/pw", envExecHome + "=/data/exec-home",
|
||||
"ARTEX_PG_DSN=postgres://artex:pw@postgres/artex", "OPENAI_API_KEY=sk-x",
|
||||
"MY_COMPANY_TOKEN=t0k3n", "ARTEX_NOISE_PROFILE=quiet", "MCP_TOKEN=abc",
|
||||
"MY_COMPANY_TOKEN=t0k3n", "LC_REVIEW_SECRET=leak", "ARTEX_NOISE_PROFILE=quiet", "MCP_TOKEN=abc",
|
||||
envExecKeep + "=MCP_TOKEN", "malformed", "=empty-name",
|
||||
}
|
||||
got := strings.Join(executorEnv(env, map[string]bool{"MCP_TOKEN": true}), "|")
|
||||
want := strings.Join([]string{
|
||||
"PATH=/usr/bin", "LANG=C.UTF-8", "LC_ALL=C", "HTTP_PROXY=http://127.0.0.1:8788",
|
||||
"PATH=/usr/bin", "LANG=C.UTF-8", "LC_ALL=C", "LC_CTYPE=C.UTF-8", "HTTP_PROXY=http://127.0.0.1:8788",
|
||||
"SSL_CERT_FILE=/ca.pem", "PLAYWRIGHT_BROWSERS_PATH=/pw", envExecHome + "=/data/exec-home",
|
||||
"MCP_TOKEN=abc",
|
||||
}, "|")
|
||||
|
||||
Reference in New Issue
Block a user