Fix leaking environment variables by Plazmaz · Pull Request #662 · gitpython-developers/GitPython
Repository navigation
Fix leaking environment variables - #662
Merged
Byron merged 2 commits into gitpython-developers:master from Plazmaz:master Sep 28, 2017
Merged
Fix leaking environment variables #662 Byron merged 2 commits into gitpython-developers:master from Plazmaz:master
Conversation
Plazmaz commented Aug 21, 2017
Copy link Copy Markdown
Contributor
When cloning a repo, GitPython will leak environment variables in error messages. For instance, this code:
import git
repo = git.Repo('https://www.github.com/Plazmaz/${PATH}')
repo.clone('testrepo/$PATH')
will output something like:
Traceback (most recent call last):
File "test.py", line 2, in <module>
repo = repo.Repo('https://www.github.com/Plazmaz/${PATH}', unsafe=True)
File "GitPython/git/repo/base.py", line 133, in __init__
raise NoSuchPathError(epath)
git.exc.NoSuchPathError: <THE CONTENTS OF $PATH>
This behavior has unwanted security implications. To counter this, I've added an unsafe variable, which will allow for environment variables to be expanded, otherwise, this behavior is disabled. By default, this variable is set to True. However, when used with environment variables, a warning is displayed. Hopefully, this will eventually be set to False by default. When running the same code, but with unsafe set to False, here's the output:
Traceback (most recent call last):
File "test.py", line 2, in <module>
repo = repo.Repo('https://www.github.com/Plazmaz/${PATH}', unsafe=False)
File "GitPython/git/repo/base.py", line 133, in __init__
raise NoSuchPathError(epath)
git.exc.NoSuchPathError:
Documents/https:/www.github.com/Plazmaz/${PATH}
ankostis
reviewed
Aug 21, 2017
View reviewed changes
ankostis left a comment
Copy link Copy Markdown
Contributor
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
Isn't this change kind of intrusive?
- Hooks expect certain variables to function, is this working with new default NOT to expand env-variables at all?
- Or break BW-compatibility with existing clients?
Outdated
|
|
||
| def _expand_path(p): | ||
| return osp.normpath(osp.abspath(osp.expandvars(osp.expanduser(p)))) | ||
| def _expand_path(p, unsafe=True): |
Outdated
| GitCommandWrapperType = Git | ||
|
|
||
| def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=False): | ||
| def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=False , unsafe=True ): |
Fix leaking environment variables
54709d9
Fixed missing parameter and changed name
67291f0
codecov-io commented Aug 24, 2017
Copy link Copy Markdown
Codecov Report
@@ Coverage Diff @@ ## master #662 +/- ## ========================================= + Coverage 92.57% 94.37% +1.8% ========================================= Files 61 61 Lines 9968 9976 +8 ========================================= + Hits 9228 9415 +187 + Misses 740 561 -179
Continue to review full report at Codecov .
|
Plazmaz commented Aug 24, 2017
Copy link Copy Markdown
Contributor
Author
|
Regarding compatibility, this is OFF by default for now. It will work with existing projects just fine. |
67291f0
into
gitpython-developers : master
Sep 28, 2017
Byron commented Sep 28, 2017
Copy link Copy Markdown
Member
|
Thanks a lot for your contribution! |