Skip to content

Tree view does not strip terminal escape sequences from file/directory names, allowing injection via a crafted filename #1188

Closed

Description

@carfeii

Summary

broot's interactive tree view displays each file and directory's name
taken directly from the filesystem with no sanitization of control
characters (src/tree_build/builder.rs and TreeLine::unprune in
src/tree/tree_line.rs both use a plain to_string_lossy()
conversion; the name field's own doc comment says "some chars may
have been stripped", but no such stripping exists anywhere in the
codebase). Since a file or directory name is fully attacker-controlled
on any system where an unprivileged local user can create files, and
browsing a directory with broot is a routine, primary use of the tool
rather than an action taken with awareness of viewing untrusted content,
any escape sequence embedded in a file or directory name reaches the
viewer's terminal unmodified.

The verb/command-execution system was checked first and found properly
defended (POSIX escaping is correctly applied when building a shell
command string, and a separate, unescaped path is used for building
argv tokens where no shell is involved); this finding is specifically
about the tree view's own rendering of names, not command execution.

Validated against v1.58.0.

POC

(available upon request)

Impact

I validated this by creating a file whose name contained a raw OSC 52
(clipboard-write) escape sequence wrapping a benign base64-encoded
marker, then running broot on that directory inside a tmux session and
capturing the literal byte stream broot wrote to its pty via tmux pipe-pane (which taps the raw bytes before tmux's own screen-buffer
interpretation, avoiding an ambiguity that a plain screen-content
capture would have left unresolved). The captured stream contained the
exact injected sequence, unmodified, directly between broot's own
color-styling escape codes, confirming broot writes it to the terminal
without any stripping. I used a benign clipboard-write marker
specifically to confirm the sequence reaches output unstripped, rather
than a more aggressive payload; the specific range of what an injected
OSC/CSI sequence can do depends on the victim's terminal emulator and
was not enumerated further.

Suggested Fix

Strip or escape control characters, particularly the ESC byte, from
file and directory names before storing them in a TreeLine's name field.
Since the field's doc comment already states an intent to do this,
centralizing name construction behind a helper that performs this
filtering would prevent the gap from being reintroduced at either of
the two places a name is currently built.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions