POSIX: Invalid handling of parameter values starting with double quotes (`"`), e.g. `--order-by='"quoted"` value'
See original GitHub issueImportant: This is a follow-up issue (#891), since it was closed without possibility to give feedback, reopen or answering my follow-up questions. I really think this is clearly a bug of spectre
and it should be further investigated, because input values are MODIFIED without any developer interaction… It may also be possible, that this leads to a SECURITY FLAW because parameters are mistreated, but I’m no expert.
This also may not be reproducible in any OS (e.g. on Windows) AND also not via Debugger or IDE, since command line parameter handling is different. To reproduce the issue, I recommend using Linux and compile the given test program in release mode.
The last answer I got stated this about argument parsing:
Unfortunately, this is out of our hands. We are just parsing the args that .NET gets from its command line handler. In fact, on Windows I get different results from you with different examples.
I think, this is wrong, because at least something in spectre
seems to Trim
whitespaces (Details: https://github.com/spectreconsole/spectre.console/issues/891#issuecomment-1179605527) beause the following example does not modify parameters, while spectre
does.
// Program.cs, dotnet 6
Console.WriteLine("== Environment.CommandLine ==");
Console.WriteLine(Environment.CommandLine);
Console.WriteLine("");
Console.WriteLine("== Environment.GetCommandLineArgs() ==");
foreach(var a in Environment.GetCommandLineArgs()){
Console.WriteLine(a);
}
Console.WriteLine("");
Console.WriteLine("== args ==");
foreach(var b in args){
Console.WriteLine(b);
}
return 0;
Information
- OS: Linux, Ubuntu 18.04 LTS
- Version: 0.45
- Terminal: xterm-256color, zsh
Describe the bug
Parameter values cannot start with double quotes ("
). They are either replaced or handled completely wrong. Additionally, parameter values are TRIMMED (remove leading spaces), so adding a space to workaround this is not possible.
The following example even cuts off the parameter value and treats everything after the space as EXTRA argument, in the following case value
is handled as positional argument and not part of --order-by
:
cli-tester test --order-by '"quoted" value' input.mp3
This may be a security flaw under specific circumstances.
More examples of invalid handling:
# `quoted` instead of `"quoted" value` and cut off handling as positional argument
cli-tester test --order-by '"quoted" value' input.mp3
cli-tester test --order-by='"quoted" value' input.mp3
# `quoted` instead of `"quoted"`
cli-tester test --order-by '"quoted"' input.mp3
# `quoted` instead of ` "quoted"`
cli-tester test --order-by ' "quoted"' input.mp3
The following examples work like expected, if not starting with double quotes or single quotes are used
# `value "quoted" like expected
cli-tester test --order-by 'value "quoted"' input.mp3
# `'quoted' value` like expected
cli-tester test --order-by "'quoted' value" input.mp3
# `\"quoted" value' value` like expected
cli-tester test --order-by='\"quoted" value' input.mp3
To Reproduce
- Compile https://github.com/sandreas/tone/tree/main/cli-tester
- Run the above examples
Expected behavior
I would expect double quotes ("
) and spaces (
) CAN be a valid part of a parameter value and should not be replaced or parsed out in any way.
Issue Analytics
- State:
- Created a year ago
- Comments:29 (14 by maintainers)
Top GitHub Comments
This is the combined PR @sandreas across the various command line parsing issues, in case you want to build and try it out: https://github.com/spectreconsole/spectre.console/pull/1048
I’ve just created this PR https://github.com/spectreconsole/spectre.console/pull/1036 @sandreas (and will fix any build errors that may appear…)
As mentioned in the PR, the following three PR’s when taken jointly represent a significant enhancement to existing command line parsing behaviour: https://github.com/spectreconsole/spectre.console/pull/1036, https://github.com/spectreconsole/spectre.console/pull/1029, https://github.com/spectreconsole/spectre.console/pull/732
If it would be useful, I could merge them all into a local ‘preview’ branch for you to build and test Tone against?