fix(tui): harden EDITOR handling and SQL sort/order validation
Split EDITOR env var on whitespace so multi-word values like "code --wait" work correctly. Add allow-list switch for sort column and order direction at the query boundary to prevent future callers from passing unsanitized values into SQL.
This commit is contained in:
+10
-2
@@ -220,12 +220,20 @@ func (s *Store) List(params ListParams) ([]*Entity, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
orderCol := "e.created_at"
|
orderCol := "e.created_at"
|
||||||
if params.Sort == "use_count" {
|
switch params.Sort {
|
||||||
|
case "use_count":
|
||||||
orderCol = "e.use_count"
|
orderCol = "e.use_count"
|
||||||
|
case "created_at", "":
|
||||||
|
orderCol = "e.created_at"
|
||||||
|
default:
|
||||||
|
orderCol = "e.created_at"
|
||||||
}
|
}
|
||||||
orderDir := "DESC"
|
orderDir := "DESC"
|
||||||
if strings.EqualFold(params.Order, "asc") {
|
switch strings.ToLower(params.Order) {
|
||||||
|
case "asc":
|
||||||
orderDir = "ASC"
|
orderDir = "ASC"
|
||||||
|
default:
|
||||||
|
orderDir = "DESC"
|
||||||
}
|
}
|
||||||
|
|
||||||
limit := params.Limit
|
limit := params.Limit
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package tui
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/atotto/clipboard"
|
"github.com/atotto/clipboard"
|
||||||
@@ -179,10 +180,12 @@ func loadTags(store *db.Store) tea.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func editInEditor(store *db.Store, e *db.Entity) tea.Cmd {
|
func editInEditor(store *db.Store, e *db.Entity) tea.Cmd {
|
||||||
editor := os.Getenv("EDITOR")
|
editorEnv := os.Getenv("EDITOR")
|
||||||
if editor == "" {
|
if editorEnv == "" {
|
||||||
editor = "vi"
|
editorEnv = "vi"
|
||||||
}
|
}
|
||||||
|
parts := strings.Fields(editorEnv)
|
||||||
|
editor, editorArgs := parts[0], parts[1:]
|
||||||
|
|
||||||
f, err := os.CreateTemp("", "nib-edit-*.md")
|
f, err := os.CreateTemp("", "nib-edit-*.md")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -195,7 +198,7 @@ func editInEditor(store *db.Store, e *db.Entity) tea.Cmd {
|
|||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
c := exec.Command(editor, f.Name())
|
c := exec.Command(editor, append(editorArgs, f.Name())...)
|
||||||
return tea.ExecProcess(c, func(err error) tea.Msg {
|
return tea.ExecProcess(c, func(err error) tea.Msg {
|
||||||
defer os.Remove(f.Name())
|
defer os.Remove(f.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user