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

Debugger environment variables not escaped in Bash #61056

Closed
Brcrwilliams opened this issue Oct 16, 2018 · 4 comments
Closed

Debugger environment variables not escaped in Bash #61056

Brcrwilliams opened this issue Oct 16, 2018 · 4 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues *duplicate Issue identified as a duplicate of another issue(s)

Comments

@Brcrwilliams
Copy link

  • VSCode Version: 1.28.1
  • OS Version: Windows 10 Enterprise 1709

So, I am having the same issue described in #50302 except with the bash shell.
The issue is here: https://github.com/Microsoft/vscode/blob/release/1.28/src/vs/workbench/parts/debug/node/terminals.ts#L407

Args are wrapped in double-quotes, but only the double-quote is escaped. This means that bash characters such as ! | $ ${} $() still do their "special" behavior. I think these args should be wrapped in single-quotes instead.

Steps to Reproduce:

  1. Install the Python extension
  2. Create a workspace with a .env file in the root of the workspace with the contents: PASSWORD=some!password
  3. Create any .py file
  4. Attempt to run the debugger
  5. Observe result:
cd "c:\Users\<username>\test" ; env "PASSWORD=some!password" "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1" "C:\Users\<username>\AppData\Local\Programs\Python\Python37\python.exe" "c:\Users\<username>\.vscode\extensions\ms-python.python-2018.
9.0\pythonFiles\experimental\ptvsd_launcher.py" 42928 "c:\Users\<username>\test\hello.py"
bash: !password: event not found

Does this issue occur when all extensions are disabled?: Probably not, but per #50302, the extension developer calls a VSCode API to do this.

If maintainers agree with my solution (wrapping args in single-quotes instead of double-quotes) then I can create a PR for this.

@isidorn isidorn assigned weinand and unassigned isidorn Oct 17, 2018
@weinand weinand added debug Debug viewlet, configurations, breakpoints, adapter issues bug Issue identified by VS Code Team member as probable bug labels Oct 17, 2018
@Brcrwilliams
Copy link
Author

Brcrwilliams commented Oct 20, 2018

Hey there, I have opened PR #61409 as a fix for this issue. I ended up just wrapping all of the args in single-quotes. This fixes the particular issue I am having. Now when I launch the debugger, it looks something like this:

test.py

from os import environ

print(environ.get('PASSWORD'))

.env

PASSWORD=test'!?$(echo foo)

launching test.py

[13:41:19] ~/test $ cd '/Users/Brian/test' ; env 'PASSWORD=test'\''!?$(echo foo)' 'PYTHONIOENCODING=UTF-8' 'PYTHONUNBUFFERED=1' 'python' '/Users/Brian/.vscode-oss-dev/extensions/ms-python.python-2018.9.1/pythonFiles/experimental/ptvsd_launcher.py' '50950' '/Users/Brian/test/test.py'
test'!?$(echo foo)

Works fine. One thing I am wondering though is if allowing special characters to be evaluated is an intended use of the TerminalLauncher? Might someone want to pass an arg like $(pwd)/some/path? I am not familiar enough with the API and its usage to make the call on whether or not that should be allowed, but I think doing it this way will avoid any unexpected errors like the case with the environment variables. Elsewise, extension authors need to do their own escaping and it will likely cause more bugs / vulnerabilities, and generally makes the behavior of the tool less predictable.

Brcrwilliams added a commit to Brcrwilliams/vscode that referenced this issue Oct 20, 2018
The TerminalLauncher does not properly escape arguments for the Bash
shell. This change wraps all arguments in single-quotes, and escapes the
single quote. This means that bash special characters in arguments will not be
evaluated.
@Brcrwilliams
Copy link
Author

Bump
@weinand, could you or another maintainer please review my PR? This issue impacts my workflow on a daily basis and I'd love to get it fixed.

@weinand weinand added this to the December 2018 milestone Dec 13, 2018
@weinand
Copy link
Contributor

weinand commented Feb 24, 2019

/duplicate #61902

@vscodebot vscodebot bot added the *duplicate Issue identified as a duplicate of another issue(s) label Feb 24, 2019
@vscodebot
Copy link

vscodebot bot commented Feb 24, 2019

Thanks for creating this issue! We figured it's covering the same as another one we already have. Thus, we closed this one as a duplicate. You can search for existing issues here. See also our issue reporting guidelines.

Happy Coding!

@vscodebot vscodebot bot closed this as completed Feb 24, 2019
@weinand weinand removed this from the February 2019 milestone Feb 24, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Apr 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues *duplicate Issue identified as a duplicate of another issue(s)
Projects
None yet
Development

No branches or pull requests

3 participants