diff --git a/core/execution.py b/core/execution.py index a03edae..1bba437 100644 --- a/core/execution.py +++ b/core/execution.py @@ -105,6 +105,9 @@ class CommandRunner: stdout=staged, stderr=subprocess.DEVNULL, shell=False, + # Resolve bare executables via the OS default path and + # exclude ambient credentials and runtime overrides. + env={"PATH": os.defpath, "LC_ALL": "C"}, start_new_session=True, ) diff --git a/tests/unit/test_execution.py b/tests/unit/test_execution.py index 75910de..a2fab4c 100644 --- a/tests/unit/test_execution.py +++ b/tests/unit/test_execution.py @@ -1,8 +1,11 @@ import io +import json +import os import sys import tempfile import unittest from pathlib import Path +from unittest.mock import patch from core.execution import ( ExecutionError, @@ -43,6 +46,23 @@ class ExecutionTests(unittest.TestCase): b"SUCCESS\n", ) + def test_subprocess_environment_excludes_parent_credentials(self): + + command = self.command( + "import json, os; print(json.dumps(dict(os.environ), sort_keys=True))" + ) + output = io.BytesIO() + with patch.dict(os.environ, { + "PATH": "/untrusted", + "LC_ALL": "untrusted", + "ABSDEV_TEST_SECRET": "synthetic", + "DOCKER_HOST": "synthetic", + "PGPASSWORD": "synthetic", + }): + self.runner(command)(command, output) + + self.assertEqual(json.loads(output.getvalue()), {"PATH": os.defpath, "LC_ALL": "C"}) + def test_binary_output_preserved(self): command = self.command(