fix: block rustup toolchain env overrides [AI] (#91615)

* fix: block rustup toolchain env overrides [AI]

* test: cover inherited rustup env stripping [AI]

* fix: preserve inherited rustup env [AI]

* fix: filter ignored opengrep changed paths [AI]

* fix: honor opengrep ignored directory globs [AI]

* fix: match ignored opengrep descendants [AI]

* fix: cover rustup mirror overrides [AI]

* fix: preserve opengrep directory-only ignores [AI]

* chore: drop opengrep cleanup from rustup fix [AI]
This commit is contained in:
Pavan Kumar Gondhi
2026-06-09 20:03:32 +05:30
committed by GitHub
parent 9f413acc18
commit 7cdec28706
5 changed files with 61 additions and 2 deletions
@@ -433,6 +433,11 @@ enum HostEnvSecurityPolicy {
"REQUESTS_CA_BUNDLE",
"RUSTC_WRAPPER",
"RUSTFLAGS",
"RUSTUP_DIST_ROOT",
"RUSTUP_DIST_SERVER",
"RUSTUP_HOME",
"RUSTUP_TOOLCHAIN",
"RUSTUP_UPDATE_ROOT",
"R_LIBS_USER",
"SSH_ASKPASS",
"SSH_AUTH_SOCK",
+10
View File
@@ -191,6 +191,11 @@
"PYTHONUSERBASE",
"RUSTC_WRAPPER",
"RUSTFLAGS",
"RUSTUP_DIST_ROOT",
"RUSTUP_DIST_SERVER",
"RUSTUP_HOME",
"RUSTUP_TOOLCHAIN",
"RUSTUP_UPDATE_ROOT",
"CARGO_HOME",
"VIRTUAL_ENV",
"LUA_PATH",
@@ -275,6 +280,11 @@
"NO_PROXY",
"PAGER",
"REQUESTS_CA_BUNDLE",
"RUSTUP_DIST_ROOT",
"RUSTUP_DIST_SERVER",
"RUSTUP_HOME",
"RUSTUP_TOOLCHAIN",
"RUSTUP_UPDATE_ROOT",
"SSH_AUTH_SOCK",
"SSL_CERT_DIR",
"SSL_CERT_FILE",
@@ -224,6 +224,11 @@
"REQUESTS_CA_BUNDLE",
"RUSTC_WRAPPER",
"RUSTFLAGS",
"RUSTUP_DIST_ROOT",
"RUSTUP_DIST_SERVER",
"RUSTUP_HOME",
"RUSTUP_TOOLCHAIN",
"RUSTUP_UPDATE_ROOT",
"R_LIBS_USER",
"SSH_ASKPASS",
"SSH_AUTH_SOCK",
@@ -252,5 +257,5 @@
"YARN_RC_FILENAME",
"ZDOTDIR"
],
"expectedTotalReportedEntries": 247
"expectedTotalReportedEntries": 252
}
@@ -46,6 +46,11 @@ const INHERITED_ALLOWLIST_RATIONALE: Record<string, string> = {
NO_PROXY: "Trusted inherited proxy bypass list from operator runtime.",
PAGER: "Trusted inherited default pager preference.",
REQUESTS_CA_BUNDLE: "Trusted inherited Python requests CA bundle path.",
RUSTUP_DIST_ROOT: "Trusted inherited deprecated Rust static download mirror.",
RUSTUP_DIST_SERVER: "Trusted inherited Rust static download mirror.",
RUSTUP_HOME: "Trusted inherited Rust toolchain root selected by operator runtime.",
RUSTUP_TOOLCHAIN: "Trusted inherited Rust toolchain selector selected by operator.",
RUSTUP_UPDATE_ROOT: "Trusted inherited Rust self-update download mirror.",
SSH_AUTH_SOCK: "Trusted inherited SSH agent socket from operator runtime.",
SSL_CERT_DIR: "Trusted inherited OpenSSL certificate directory path.",
SSL_CERT_FILE: "Trusted inherited OpenSSL certificate file path.",
@@ -92,7 +97,7 @@ describe("host env reported baseline coverage", () => {
baseline.reportedDangerousEverywhereKeys.length +
baseline.reportedDangerousOverrideOnlyKeys.length,
).toBe(baseline.expectedTotalReportedEntries);
expect(baseline.expectedTotalReportedEntries).toBe(247);
expect(baseline.expectedTotalReportedEntries).toBe(252);
expect(sortUniqueUpper(baseline.reportedDangerousEverywhereKeys)).toEqual(
baseline.reportedDangerousEverywhereKeys,
);
+34
View File
@@ -160,6 +160,10 @@ describe("isDangerousHostEnvVarName", () => {
expect(isDangerousHostEnvVarName("CARGO_BUILD_RUSTC_WRAPPER")).toBe(true);
expect(isDangerousHostEnvVarName("cargo_build_rustc_wrapper")).toBe(true);
expect(isDangerousHostEnvVarName("cargo_home")).toBe(false);
expect(isDangerousHostEnvVarName("RUSTUP_DIST_SERVER")).toBe(false);
expect(isDangerousHostEnvVarName("RUSTUP_HOME")).toBe(false);
expect(isDangerousHostEnvVarName("rustup_update_root")).toBe(false);
expect(isDangerousHostEnvVarName("rustup_toolchain")).toBe(false);
expect(isDangerousHostEnvVarName("CMAKE_C_COMPILER")).toBe(true);
expect(isDangerousHostEnvVarName("cmake_c_compiler")).toBe(true);
expect(isDangerousHostEnvVarName("CMAKE_CXX_COMPILER")).toBe(true);
@@ -337,6 +341,11 @@ describe("sanitizeHostExecEnv", () => {
AWS_CONFIG_FILE: "/tmp/aws-config",
SSH_AUTH_SOCK: "/tmp/trusted-ssh-agent.sock",
CARGO_HOME: "/tmp/cargo",
RUSTUP_DIST_ROOT: "https://mirror.example.test/deprecated-dist",
RUSTUP_DIST_SERVER: "https://mirror.example.test",
RUSTUP_HOME: "/tmp/rustup-home",
RUSTUP_TOOLCHAIN: "/tmp/rustup-toolchain",
RUSTUP_UPDATE_ROOT: "https://mirror.example.test/rustup",
HELM_HOME: "/tmp/helm",
HTTP_PROXY: "http://proxy.example.test:8080",
HTTPS_PROXY: "http://proxy.example.test:8443",
@@ -373,6 +382,11 @@ describe("sanitizeHostExecEnv", () => {
SSL_CERT_DIR: "/tmp/evil-cert-dir",
DOCKER_CONTEXT: "trusted-remote",
DOCKER_HOST: "tcp://docker.example.test:2376",
RUSTUP_DIST_ROOT: "https://mirror.example.test/deprecated-dist",
RUSTUP_DIST_SERVER: "https://mirror.example.test",
RUSTUP_HOME: "/tmp/rustup-home",
RUSTUP_TOOLCHAIN: "/tmp/rustup-toolchain",
RUSTUP_UPDATE_ROOT: "https://mirror.example.test/rustup",
OK: "1",
});
});
@@ -902,6 +916,11 @@ describe("isDangerousHostEnvOverrideVarName", () => {
expect(isDangerousHostEnvOverrideVarName("rustc_wrapper")).toBe(true);
expect(isDangerousHostEnvOverrideVarName("RUSTFLAGS")).toBe(true);
expect(isDangerousHostEnvOverrideVarName("rustflags")).toBe(true);
expect(isDangerousHostEnvOverrideVarName("RUSTUP_DIST_ROOT")).toBe(true);
expect(isDangerousHostEnvOverrideVarName("rustup_dist_server")).toBe(true);
expect(isDangerousHostEnvOverrideVarName("RUSTUP_HOME")).toBe(true);
expect(isDangerousHostEnvOverrideVarName("rustup_toolchain")).toBe(true);
expect(isDangerousHostEnvOverrideVarName("RUSTUP_UPDATE_ROOT")).toBe(true);
expect(isDangerousHostEnvOverrideVarName("CARGO_BUILD_RUSTC_WRAPPER")).toBe(true);
expect(isDangerousHostEnvOverrideVarName("cargo_build_rustc_wrapper")).toBe(true);
expect(isDangerousHostEnvOverrideVarName("CARGO_HOME")).toBe(true);
@@ -1042,6 +1061,11 @@ describe("sanitizeHostExecEnvWithDiagnostics", () => {
PYTHONUSERBASE: "/tmp/evil-python-userbase",
RUSTC_WRAPPER: "/tmp/evil-rustc-wrapper",
RUSTFLAGS: "-C link-args=-l/tmp/evil.so",
RUSTUP_DIST_ROOT: "https://evil.example.test/deprecated-dist",
RUSTUP_DIST_SERVER: "https://evil.example.test",
RUSTUP_HOME: "/tmp/evil-rustup-home",
RUSTUP_TOOLCHAIN: "/tmp/evil-toolchain",
RUSTUP_UPDATE_ROOT: "https://evil.example.test/rustup",
VIRTUAL_ENV: "/tmp/evil-venv",
JAVA_OPTS: "-javaagent:/tmp/evil.jar",
YARN_RC_FILENAME: ".evil-yarnrc.yml",
@@ -1117,6 +1141,11 @@ describe("sanitizeHostExecEnvWithDiagnostics", () => {
"REQUESTS_CA_BUNDLE",
"RUSTC_WRAPPER",
"RUSTFLAGS",
"RUSTUP_DIST_ROOT",
"RUSTUP_DIST_SERVER",
"RUSTUP_HOME",
"RUSTUP_TOOLCHAIN",
"RUSTUP_UPDATE_ROOT",
"SSL_CERT_DIR",
"SSL_CERT_FILE",
"UV_DEFAULT_INDEX",
@@ -1197,6 +1226,11 @@ describe("sanitizeHostExecEnvWithDiagnostics", () => {
expect(result.env.PYTHONUSERBASE).toBeUndefined();
expect(result.env.RUSTC_WRAPPER).toBeUndefined();
expect(result.env.RUSTFLAGS).toBeUndefined();
expect(result.env.RUSTUP_DIST_ROOT).toBeUndefined();
expect(result.env.RUSTUP_DIST_SERVER).toBeUndefined();
expect(result.env.RUSTUP_HOME).toBeUndefined();
expect(result.env.RUSTUP_TOOLCHAIN).toBeUndefined();
expect(result.env.RUSTUP_UPDATE_ROOT).toBeUndefined();
expect(result.env.VIRTUAL_ENV).toBeUndefined();
expect(result.env.YARN_RC_FILENAME).toBeUndefined();
});