From 621e280451f217b772e0f047bc5fc10a9832b8c0 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 13 Dec 2019 21:00:34 +0100 Subject: [PATCH] Make sure that you can select virtualenvs more precisely, fixes #1407 --- jedi/api/environment.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/jedi/api/environment.py b/jedi/api/environment.py index 0f23e3d4..8f850e45 100644 --- a/jedi/api/environment.py +++ b/jedi/api/environment.py @@ -261,34 +261,37 @@ def find_virtualenvs(paths=None, **kwargs): """ :param paths: A list of paths in your file system to be scanned for Virtualenvs. It will search in these paths and potentially execute the - Python binaries. Also the VIRTUAL_ENV variable will be checked if it - contains a valid Virtualenv. And CONDA_PREFIX will be checked to see - if it contains a valid conda environment. + Python binaries. :param safe: Default True. In case this is False, it will allow this function to execute potential `python` environments. An attacker might be able to drop an executable in a path this function is searching by default. If the executable has not been installed by root, it will not be executed. + :param use_environment_vars: Default True. If True, the VIRTUAL_ENV + variable will be checked if it contains a valid VirtualEnv. + CONDA_PREFIX will be checked to see if it contains a valid conda + environment. :yields: :class:`Environment` """ - def py27_comp(paths=None, safe=True): + def py27_comp(paths=None, safe=True, use_environment_vars=True): if paths is None: paths = [] _used_paths = set() - # Using this variable should be safe, because attackers might be able - # to drop files (via git) but not environment variables. - virtual_env = _get_virtual_env_from_var() - if virtual_env is not None: - yield virtual_env - _used_paths.add(virtual_env.path) + if use_environment_vars: + # Using this variable should be safe, because attackers might be + # able to drop files (via git) but not environment variables. + virtual_env = _get_virtual_env_from_var() + if virtual_env is not None: + yield virtual_env + _used_paths.add(virtual_env.path) - conda_env = _get_virtual_env_from_var(_CONDA_VAR) - if conda_env is not None: - yield conda_env - _used_paths.add(conda_env.path) + conda_env = _get_virtual_env_from_var(_CONDA_VAR) + if conda_env is not None: + yield conda_env + _used_paths.add(conda_env.path) for directory in paths: if not os.path.isdir(directory):