Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a clean, whitelisted environment with Popen (#16118) #16119

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions conan/cli/cli.py
Expand Up @@ -242,6 +242,54 @@ def _warn_python_version():
ConanOutput().warning("Python 3.6 is end-of-life since 2021. "
"Conan future versions will drop support for it, "
"please upgrade Python", warn_tag="deprecated")
def _clear_env():
if True: # if platform.system() == 'Windows':
whitelist_env_keys = [
'ALLUSERSPROFILE',
'APPDATA',
'COMMONPROGRAMFILES(X86)',
'COMMONPROGRAMFILES',
'COMMONPROGRAMW6432',
'COMPUTERNAME',
'COMSPEC',
'DRIVERDATA',
'HOMEDRIVE',
'HOMEPATH',
'LOCALAPPDATA',
'LOGONSERVER',
'NUMBER_OF_PROCESSORS',
'OS',
'PATHEXT',
'PROCESSOR_ARCHITECTURE',
'PROCESSOR_IDENTIFIER',
'PROCESSOR_LEVEL',
'PROCESSOR_REVISION',
'PROGRAMDATA',
'PROGRAMFILES(X86)',
'PROGRAMFILES',
'PROGRAMW6432',
'PSMODULEPATH',
'PUBLIC',
'SESSIONNAME',
'SYSTEMDRIVE',
'SYSTEMROOT',
'SYSTEMROOT',
'TEMP',
'TMP',
'USERDOMAIN',
'USERDOMAIN_ROAMINGPROFILE',
'USERNAME',
'USERPROFILE',
'WINDIR',
]
for key in list(os.environ.keys()):
if key not in whitelist_env_keys:
del os.environ[key]
# Also get the path to conan's python, as some packages assume access to python
# eg dav1d
# This will also give access to ninja.exe and whatever else is installed in the devenv
python_path = os.path.dirname(sys.executable)
os.environ['PATH'] = f'C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0;{python_path}'


def main(args):
Expand Down Expand Up @@ -285,6 +333,8 @@ def ctrl_break_handler(_, __):
if sys.platform == 'win32':
signal.signal(signal.SIGBREAK, ctrl_break_handler)

_clear_env()

cli = Cli(conan_api)
error = SUCCESS
try:
Expand Down