Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions e2e/sandbox/test_sandbox_task
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ cat >mise.toml <<'TOML'
[tasks.env_test]
run = "echo ${SANDBOX_TASK_SECRET:-empty}"
deny_env = true

[tasks.path_test]
run = 'echo "PATH=${PATH:-unset} HOME=${HOME:-unset}"'
deny_env = true
TOML

export SANDBOX_TASK_SECRET="should_not_see"

# Task with deny_env should not see the var
assert "mise run env_test" "empty"

# deny_env should still let essential vars (PATH, HOME, ...) through
assert_not_contains "mise run path_test" "PATH=unset"
assert_not_contains "mise run path_test" "HOME=unset"
11 changes: 10 additions & 1 deletion src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,18 @@ impl<'a> CmdLineRunner<'a> {

#[cfg(target_os = "linux")]
{
// On Linux, clear inherited env before pre_exec so child only sees filtered vars
// On Linux, clear inherited env before pre_exec so child only sees filtered vars.
// env_clear() also wipes envs explicitly set via .envs(), so save and restore them.
if sandbox.effective_deny_env() {
let saved: Vec<(std::ffi::OsString, std::ffi::OsString)> = self
.cmd
.get_envs()
.filter_map(|(k, v)| v.map(|v| (k.to_os_string(), v.to_os_string())))
.collect();
self.cmd.env_clear();
for (k, v) in saved {
self.cmd.env(k, v);
}
}
// Use pre_exec to apply Landlock/seccomp in the child process
// before it execs the target program. This avoids restricting the mise process.
Expand Down
Loading