BUG: Potential command injection in EDITOR environment variable parsing
Describe the bug In main.go line 2254 and cli/config.go line 38, $EDITOR environment variable is parsed using strings.Fields() which splits on whitespace but doesn't handle shell quoting or escaping properly. This could lead to command injection if EDITOR contains quotes or special characters.
To reproduce
- Examine main.go lines 2254-2256:
parts := strings.Fields(editor)
args := append(parts[1:], tmpPath)
c := exec.Command(parts[0], args...)
- Set malicious EDITOR value:
export EDITOR='vim "; malicious-command #'
- While exec.Command() doesn't invoke shell (safe from direct shell injection), strings.Fields() can misparse quoted arguments
Expected behavior Use proper shell word splitting that respects quotes, or validate EDITOR contains only alphanumeric/path characters, or use shellquote library.
Additional context
- Good first issue: straightforward input validation
- Low severity: requires user to set malicious EDITOR (local attack surface)
- exec.Command() doesn't invoke shell so not direct shell injection
- But strings.Fields() breaks on space even inside quotes
- Example:
EDITOR='emacs -nw'works, butEDITOR='code --wait'also works - Real issue: if editor path contains spaces even with quotes, Fields() splits incorrectly
Suggested fix (option 1 - validate):
editor := os.Getenv("EDITOR")
if editor == "" {
editor = "vi"
}
// Only allow safe characters in EDITOR
if !regexp.MustCompile(`^[a-zA-Z0-9/_.-]+(\s+[a-zA-Z0-9/_.-]+)*$`).MatchString(editor) {
return func() tea.Msg {
return tui.EditorFinishedMsg{Err: fmt.Errorf("invalid EDITOR: contains unsafe characters")}
}
}
Suggested fix (option 2 - use shellquote):
import "github.com/kballard/go-shellquote"
parts, err := shellquote.Split(editor)
if err != nil || len(parts) == 0 {
parts = []string{"vi"}
}
args := append(parts[1:], tmpPath)
c := exec.Command(parts[0], args...)
OS All platforms
This has had no activity for 30 days. It will be closed in 14 days unless updated. Comment or remove the stale label to keep it open.
Closing due to inactivity. Reopen if still relevant.