-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(auth): correctly parse executable command with quoted arguments #13296
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
base: main
Are you sure you want to change the base?
fix(auth): correctly parse executable command with quoted arguments #13296
Conversation
The executable command for pluggable auth was being parsed with `strings.Fields`, which does not handle quoted arguments containing spaces correctly. This caused errors when the executable path or its arguments contained spaces. This change replaces `strings.Fields` with `shellwords.Parse` from the `github.com/mattn/go-shellwords` library. This library correctly parses shell command strings, respecting quotes. This change adds a new dependency on `github.com/mattn/go-shellwords`.
Summary of ChangesHello @nbayati, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical parsing flaw in the pluggable authentication mechanism where executable commands with spaces in their paths or arguments were incorrectly interpreted. By switching to a more sophisticated shellwords parser, the system can now reliably execute commands, significantly improving the stability and compatibility of the authentication process. This change ensures that complex command structures are handled as intended, preventing authentication failures due to malformed command execution. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly fixes an issue with parsing executable commands that contain quoted arguments with spaces. The change replaces strings.Fields with shellwords.Parse, which is the right approach for this problem. The introduction of the new dependency is justified. My feedback includes a suggestion to enhance the test coverage for the new error handling path that was introduced.
| tests := []struct { | ||
| name string | ||
| command string | ||
| want []string | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "simple command", | ||
| command: "a b c", | ||
| want: []string{"a", "b", "c"}, | ||
| }, | ||
| { | ||
| name: "quoted argument", | ||
| command: `a "b c"`, | ||
| want: []string{"a", "b c"}, | ||
| }, | ||
| { | ||
| name: "quoted executable", | ||
| command: `"a b" c`, | ||
| want: []string{"a b", "c"}, | ||
| }, | ||
| { | ||
| name: "quoted executable and argument", | ||
| command: `"a b" "c d"`, | ||
| want: []string{"a b", "c d"}, | ||
| }, | ||
| { | ||
| name: "single quotes", | ||
| command: `'a b' 'c d'`, | ||
| want: []string{"a b", "c d"}, | ||
| }, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is a good addition for verifying the new parsing logic. To improve test coverage for the new error handling in the run function, please consider adding test cases for empty and whitespace-only command strings. These inputs cause shellwords.Parse to return an empty slice, which triggers the new if len(splitCommand) == 0 check.
tests := []struct {
name string
command string
want []string
wantErr bool
}{
{
name: "simple command",
command: "a b c",
want: []string{"a", "b", "c"},
},
{
name: "quoted argument",
command: `a "b c"`,
want: []string{"a", "b c"},
},
{
name: "quoted executable",
command: `"a b" c`,
want: []string{"a b", "c"},
},
{
name: "quoted executable and argument",
command: `"a b" "c d"`,
want: []string{"a b", "c d"},
},
{
name: "single quotes",
command: `'a b' 'c d'`,
want: []string{"a b", "c d"},
},
{
name: "empty command",
command: "",
want: []string{},
},
{
name: "whitespace only",
command: " ",
want: []string{},
},
}
The executable command for pluggable auth was being parsed with
strings.Fields, which does not handle quoted arguments containing spaces correctly. This caused errors when the executable path or its arguments contained spaces.This change replaces
strings.Fieldswithshellwords.Parsefrom thegithub.com/mattn/go-shellwordslibrary. This library correctly parses shell command strings, respecting quotes.This change adds a new dependency on
github.com/mattn/go-shellwords.This was reported in b/238143555