This repository was archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Batch Changes - commit message on stdin #55657
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||
package gitdomain | ||||
|
||||
import ( | ||||
"fmt" | ||||
"os" | ||||
"strconv" | ||||
"strings" | ||||
|
@@ -141,8 +142,20 @@ func IsAllowedGitCmd(logger log.Logger, args []string) bool { | |||
logger.Warn("command not allowed", log.String("cmd", cmd)) | ||||
return false | ||||
} | ||||
|
||||
// I hate state machines, but I hate them less than complicated multi-argument checking | ||||
checkFileInput := false | ||||
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. can we get a test for this new added behavior? |
||||
for i, arg := range args[1:] { | ||||
if checkFileInput { | ||||
if arg == "-" { | ||||
checkFileInput = false | ||||
continue | ||||
} | ||||
logger.Warn("IsAllowedGitCmd: unallowed file input for `git commit`", log.String("cmd", cmd), log.String("arg", arg)) | ||||
return false | ||||
} | ||||
if strings.HasPrefix(arg, "-") { | ||||
fmt.Printf("EVALUATING ARGUMENT %d: %s\n", i, arg) | ||||
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.
Suggested change
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. I don’t feel super strongly about the other comments, but I think we should address this one in a follow up 🙂 |
||||
// Special-case `git log -S` and `git log -G`, which interpret any characters | ||||
// after their 'S' or 'G' as part of the query. There is no long form of this | ||||
// flags (such as --something=query), so if we did not special-case these, there | ||||
|
@@ -162,6 +175,24 @@ func IsAllowedGitCmd(logger log.Logger, args []string) bool { | |||
continue // this arg is OK | ||||
} | ||||
|
||||
// For `git commit`, allow reading the commit message from stdin | ||||
// but don't just blindly accept the `--file` or `-F` args | ||||
// because they could be used to read arbitrary files. | ||||
// Instead, accept only the forms that read from stdin. | ||||
if cmd == "commit" { | ||||
if arg == "--file=-" { | ||||
continue | ||||
} | ||||
// checking `-F` requires a second check for `-` in the next argument | ||||
// Instead of an obtuse check of next and previous arguments, set state and check it the next time around | ||||
// Here's the alternative obtuse check of previous and next arguments: | ||||
// (arg == "-F" && len(args) > i+2 && args[i+2] == "-") || (arg == "-" && args[i] == "-F") | ||||
if arg == "-F" { | ||||
checkFileInput = true | ||||
continue | ||||
} | ||||
} | ||||
|
||||
if !isAllowedGitArg(allowedArgs, arg) { | ||||
logger.Warn("IsAllowedGitCmd.isAllowedGitArgcmd", log.String("cmd", cmd), log.String("arg", arg)) | ||||
return false | ||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.