-
Notifications
You must be signed in to change notification settings - Fork 929
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
CLIUtils.generateArgline does not quote IFS characters other than space #298
Comments
This issue goes well beyond failing to quote non-space characters. We also don't quote quotes (so the user can, SQL-injection-style, remove themselves from same): (CLIUtils/generateArgline "run-tool" (into-array String ["''$(rm -rf /)''"])) run-tool ''$(rm -rf /)'' (Notably, paired single quotes cancel each other out, so |
(Not sure how the issue was closed, btw -- that looks like it was a PEBKAC). |
Another permutation of this issue, this one verified remotely exploitable: Glob characters are not expanded. If |
One item which substantially complicates developing a satisfactory patch for this issue: Replacing the current behavior of Consider the following example: /* current test-suite code, from TestExecTool.testGenerateArgline() */
assertEquals("invalid",
"test 1 2 \"34\"",
CLIUtils.generateArgline("test", new String[]{"1", "2", "\"34\""})); Since the input array contains literal quotes, an algorithm which faithfully represented its input array within its output would have different behavior: /* proposed test validating more defensible behavior */
assertEquals("invalid",
"test 1 2 '\"34\"'",
CLIUtils.generateArgline("test", new String[]{"1", "2", "\"34\""})); ...thereby representing the exact user-provided input, quotes intact. (Handling single quotes or mixed quotes gets a little more interesting -- but I have a working, tested implementation; it isn't submitted as a pull request only due to the conflict with preexisting semantics). |
This is the (very) beginning of a fix to rundeck#298. Unfortunately, doing this in a way that doesn't compromise backwards compatibility is out-of-scope, and will probably call for a multi-phase implementation -- for instance, adding a per-job flag to specify compatible or safe quoting, providing warnings and (eventually) deprecation notices to users with jobs using unsafe quoting, and (again, eventually) flipping the default.
Hi Charles, In examining the usage of the CLIUtils, the code actually has a few different use-cases for it:
In addition, I'm not even sure what kind of quoting is necessary to solve the same potential problem in a Windows environment. We need to refactor the usage of CLIUtils a bit more to solve shell quoting issues and remove conflation between its use-cases. So I propose we do something like this:
thoughts? also, thanks for bringing this to light and kicking off the beginning of a fix :) |
In an ideal world, we'd enhance the argLine split/generate to be able to unambiguously represent any valid C string (ie. anything not containing a NUL) as an argument. Not implementing this restricts the user without any obvious benefit. However -- that's not a trivial amount of work. I'm not familiar with any existing parser for either POSIX sh or zsh command lines implemented for Java, certainly not enough to vouch for completeness or safety. (Python has its excellent shlex module, but it's not trivial to port). [Aside: zsh was mentioned because its semantics are closer to those of rundeck's argLine format as documented and used than those of POSIX sh; in zsh, parameter expansion results are not string-split or glob-expanded, so ${foo} will always become exactly one parameter, rather than an unknown number depending on its contents]. |
need to add documentation about quoting arguments in exec strings |
For rundeck#298 Arguments to script/script-file/script-url were not being quoted. Additionally, arguments with spaces were not being quoted. If arguments have spaces even if not containing expansion variables then they are quoted.
* describe quoting rules for parsing command string and script args. * describe escaping for option values in commands and args
Newlines and tabs can be injected into generated commands unquoted. This results in direct security issues, particularly if an untrusted data source is used for options.
Consider a tool wherein a user-specified option can be one of a limited number of values, but wherein additional arguments are used to form an argv array (not an uncommon design pattern):
This generates the following command:
...or:
...which generates:
The text was updated successfully, but these errors were encountered: