Repository navigation
Fix virtualenv extraction from activate for newer virtualenvs #35
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
Changes from all commits
3a2f115
935e95b
e1241cc
427a5e5
f159894
c923fbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| import re | ||
| import shlex | ||
| import shutil | ||
| import subprocess | ||
| import sys | ||
| from types import CodeType | ||
| from typing import NamedTuple | ||
|
|
@@ -246,25 +247,13 @@ def update_paths(venv: Virtualenv, new_path: str) -> None: | |
| remove_local(venv.path) | ||
| update_scripts(venv.bin_dir, venv.orig_path, new_path, activation=True) | ||
|
|
||
|
|
||
| def get_orig_path(venv_path: str) -> str: | ||
| """This helps us know whether someone has tried to relocate the | ||
| virtualenv | ||
| """ | ||
| activate_path = os.path.join(venv_path, 'bin/activate') | ||
|
|
||
| with open(activate_path) as activate: | ||
| venv_var_prefix = 'VIRTUAL_ENV=' | ||
| for line in activate: | ||
| # virtualenv 20 changes the position | ||
| if line.startswith(venv_var_prefix): | ||
| return shlex.split(line[len(venv_var_prefix):])[0] | ||
| else: | ||
| raise AssertionError( | ||
| 'Could not find VIRTUAL_ENV= in activation script: %s' % | ||
| activate_path | ||
| ) | ||
|
|
||
| result = subprocess.run(["bash", "-c", f"source {activate_path} && echo $VIRTUAL_ENV"], capture_output=True, text=True) | ||
| return result.stdout.strip() | ||
|
Comment on lines
+255
to
+256
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this introduces several arbitrary code execution vulnerabilities:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is parsing then still the best option even though its brittle?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is the only approach I would take personally -- you'll still have problems with substitution either way
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In #36, I'm doing a str.replace for the virtualenv path. Because the bash script now has 3 lines to update, the existing regex doesn't cover all the cases. Though, maybe I should just create 2 more regexes to be more explicit about the replacement. |
||
|
|
||
| class NotAVirtualenvError(ValueError): | ||
| def __str__(self) -> str: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to consider using
shlex.quoteon theactivate_path. I think this will fail for paths with spaces or other special characters in them.