Skip to content

armgit / ARTEX

Public Imported from GitHub
0

ARTEX - AI autonomous penetration testing system (English translation; upstream: Autumn-27/ARTEX, AGPL-3.0)

server: keep only the fixed locale names in the executor environment

BaaRai60a1ffca62cd
diff --git a/server/execenv_unix.go b/server/execenv_unix.go
index 7ce71b6..b84f29d 100644
--- a/server/execenv_unix.go
+++ b/server/execenv_unix.go
@@ -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
diff --git a/server/execenv_unix_test.go b/server/execenv_unix_test.go
index d74145f..7f48eec 100644
--- a/server/execenv_unix_test.go
+++ b/server/execenv_unix_test.go
@@ -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",
}, "|")