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 hard quotes rather than soft quotes #61902 #68435

Merged
merged 4 commits into from
Feb 13, 2019

Conversation

geirha
Copy link
Contributor

@geirha geirha commented Feb 11, 2019

The current code encloses arguments in soft quotes ("...") before injecting them into the shell. Soft quotes prevent some expansions from occuring, but not all. Hard quotes ('...') on the other hand, treats everything literally, making it a much safer choice.

@weinand weinand added this to the February 2019 milestone Feb 11, 2019
@weinand weinand added the debug Debug viewlet, configurations, breakpoints, adapter issues label Feb 11, 2019
@geirha geirha force-pushed the 61902-shell-injection branch from 25fecaa to 8530c76 Compare February 12, 2019 07:20
@geirha
Copy link
Contributor Author

geirha commented Feb 12, 2019

rebased with master, so now the automated tests finally succeed. I'm unable to properly test this patch locally myself, because the integrated terminal ends up broken in my build attempts.

@weinand
Copy link
Contributor

weinand commented Feb 12, 2019

@geirha Thanks for the PR.

Two comments:

  • you modify the behavior of the quote function which is not only used for env variables and the cwd, but for args as well. Your change will break anyone who passes wildchars ('*') as arguments. I suggest to only fix the env variable issue launch.json envFile not escaped before injecting #61902 and not touch anything else.
  • The original code tried to add quotes only if needed in order to keep the resulting command readable. Please try to do the same when quoting env vars.

@geirha
Copy link
Contributor Author

geirha commented Feb 13, 2019

  • you modify the behavior of the quote function which is not only used for env variables and the cwd, but for args as well. Your change will break anyone who passes wildchars ('*') as arguments. I suggest to only fix the env variable issue launch.json envFile not escaped before injecting #61902 and not touch anything else.

I feel that'll be a messy, half-working solution, where a glob will only work if it happens to not contain space or ", regardless of how many quotes/backslashes the user throws at it. I'd suggest instead that the glob expansion be done by vscode, and then pass the resulting file lists safely quoted. Though unfortunately there's no builtin glob function(s) in either js or node.js that I know of, but there are some available via npm of course. Not sure what the politics of introducing new deps is..? I see there's a glob in devDependencies already.

  • The original code tried to add quotes only if needed in order to keep the resulting command readable. Please try to do the same when quoting env vars.

I thought about adding a whitelist of characters not needing quoting. but went with trying to make the patch small instead. I can add such a whitelist.

@geirha geirha force-pushed the 61902-shell-injection branch from 61f1696 to 05fcf17 Compare February 13, 2019 07:32
@weinand
Copy link
Contributor

weinand commented Feb 13, 2019

The scope of your PR is to address a problem with env variables #61902, not to fix globbing issues (that are not even mentioned in the original comment).
Please keep in mind that there are quite a few launch configurations out there that we don't want to break unnecessarily.

If you want to address globbing issues, please create a separate issue first.

@geirha
Copy link
Contributor Author

geirha commented Feb 13, 2019

Fair enough. So I reverted the quote function to its previous state, and introduced a new hardQuote function for the cwd and env vars, including a whitelist to avoid it needlessly quoting words that don't contain any shell metacharacters.

@weinand weinand merged commit 1b1815a into microsoft:master Feb 13, 2019
@weinand
Copy link
Contributor

weinand commented Feb 13, 2019

Thanks for the PR.
I will limit the use of hardQuote to env variables only in a subsequent commit.

@weinand
Copy link
Contributor

weinand commented Feb 26, 2019

@geirha The change from ';' to '&&' in your PR resulted in regression #68997 (and I as the reviewer did not notice that).
This is another good example why PRs should never contain unnecessary changes.

@geirha
Copy link
Contributor Author

geirha commented Feb 27, 2019

@weinand Ouch. It never occured to me that this could be used with other than bourne-style shells. Especially since the code in question is inside a case ShellType.bash:

The hard-quoting might also be wrong then; it's safe for bash, and any other bourne-style shells I know of, but I have no idea if fish has the same quoting rules, nor whether the whitelisted characters are safe to leave unquoted.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants