-
Notifications
You must be signed in to change notification settings - Fork 352
fix: double-quote --allow-domains args containing ${{ }} expressions
#25721
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
Changes from 4 commits
43bd43e
addc2e8
351cd81
3d147d8
dc5847d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,9 @@ | |
|
|
||
| var shellLog = logger.New("workflow:shell") | ||
|
|
||
| // shellJoinArgs joins command arguments with proper shell escaping | ||
| // Arguments containing special characters are wrapped in single quotes | ||
| // shellJoinArgs joins command arguments with proper shell escaping. | ||
| // Arguments containing ${{ }} GitHub Actions expressions are double-quoted; | ||
| // other arguments with special shell characters are single-quoted. | ||
| func shellJoinArgs(args []string) string { | ||
| shellLog.Printf("Joining %d shell arguments with escaping", len(args)) | ||
| var escapedArgs []string | ||
|
|
@@ -21,9 +22,21 @@ | |
| return result | ||
| } | ||
|
|
||
| // shellEscapeArg escapes a single argument for safe use in shell commands | ||
| // Arguments containing special characters are wrapped in single quotes | ||
| // shellEscapeArg escapes a single argument for safe use in shell commands. | ||
| // Arguments containing ${{ }} GitHub Actions expressions are double-quoted; | ||
| // other arguments with special shell characters are single-quoted. | ||
| func shellEscapeArg(arg string) string { | ||
| // If the argument contains GitHub Actions expressions (${{ }}), use double-quote | ||
| // wrapping. GitHub Actions evaluates ${{ }} at the YAML level before the shell runs, | ||
| // so single-quoting would mangle the expression syntax (e.g., 'staging' inside | ||
| // ${{ env.X == 'staging' }} becomes '\''staging'\'' which GA cannot parse). | ||
| // Double-quoting preserves the expression for GA evaluation. | ||
| if containsGitHubActionsExpression(arg) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The double-quote wrapping for GitHub Actions expressions is a great fix! One small note: since GitHub Actions evaluates |
||
| shellLog.Print("Argument contains GitHub Actions expression, using double-quote wrapping") | ||
| escaped := strings.ReplaceAll(arg, `"`, `\"`) | ||
| return `"` + escaped + `"` | ||
| } | ||
|
|
||
| // Check if the argument contains special shell characters that need escaping | ||
| if strings.ContainsAny(arg, "()[]{}*?$`\"'\\|&;<> \t\n") { | ||
| shellLog.Print("Argument contains special characters, applying escaping") | ||
|
|
@@ -36,6 +49,16 @@ | |
| return arg | ||
| } | ||
|
|
||
| // containsGitHubActionsExpression checks if a string contains GitHub Actions | ||
| // expressions (${{ ... }}). It verifies that ${{ appears before }}. | ||
| func containsGitHubActionsExpression(s string) bool { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| openIdx := strings.Index(s, "${{") | ||
| if openIdx < 0 { | ||
| return false | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good defensive check: |
||
| } | ||
| return strings.Index(s[openIdx:], "}}") >= 0 | ||
| } | ||
|
|
||
| // buildDockerCommandWithExpandableVars builds a properly quoted docker command | ||
| // that allows ${GITHUB_WORKSPACE} and $GITHUB_WORKSPACE to be expanded at runtime | ||
| func buildDockerCommandWithExpandableVars(cmd string) string { | ||
|
|
||
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.
The double-quote wrapping for GA expressions looks correct. One edge case to consider: if the expression itself produces a value with embedded double quotes at runtime, those would break the shell command. The
ReplaceAllon line 34 handles literal double quotes in the source, but runtime-evaluated values aren't covered here (that would be a separate concern).