The mode itself decides what programs are told, over the ordinary terminfo
protocol - there is nothing to turn on. A CLI-mode tab reports
TERM=secure-terminal, a restricted entry, so a well-behaved program adapts at the
source: a pager, a completion menu or a progress bar that would otherwise address the cursor or
clear the screen instead prints plain line-by-line output it knows this terminal can show -
cleaner to read, with less stripped-escape noise, and the terminal is never even asked to do
something it refuses. A TUI-mode tab reports the fuller xterm-256color, so
full-screen programs and remote hosts (over ssh) get the entry they need.
The secure-terminal entry inherits the correct colour and SGR
capabilities from xterm-16color, then cancels every capability CLI mode
does not render - cursor addressing, the alternate screen, clear/erase-display, insert/delete
line and character, scroll regions, save/restore cursor, tab stops, the title and status
line, mouse - and the u6/u7/u8/u9
device-query capabilities. So a well-behaved program emits only what this terminal actually
shows (line-local moves plus colour) and never probes a terminal that will not answer.
It is defence in depth, not the guarantee: the renderer strips those sequences regardless of
TERM; this just stops them being generated.
Switching a tab between CLI and TUI re-exports TERM to the running shell as a
plain, visible export TERM=... command - the shell re-reads terminfo live,
so no restart and no lost shell state. The switch is refused (with a message) while a program
is running, since it owns the terminal. The entry is a short, readable source file:
secure-terminal.ti.
Three terminfo entries, three points on a spectrum:
dumb (the classic "line-oriented, no cursor control" entry every system already
ships), secure-terminal (CLI mode's safe-but-comfortable subset), and
xterm-256color (TUI mode's full standard entry). CLI's two entries WITHHOLD cursor
addressing so a program cannot redraw; TUI advertises the full entry and instead confines what a
program draws to a neutralised pyte grid. Note that dumb reaches the core safety by
having almost nothing - no colour, no bold, not even cursor-left, so an interactive shell cannot
edit within a line - while secure-terminal keeps the safe, useful, line-local half
of a real terminal and cancels only the dangerous half.
The entry advertises... (all three are values secure-terminal sets for TERM) |
TERM=dumb |
TERM=secure-terminal (CLI mode) |
TERM=xterm-256color (TUI mode) |
| Cursor addressing / alternate screen (full-screen redraw) |
Refused | Refused |
Advertised * |
| Tab-completions |
Listed | Listed | Drawn as a cursor menu |
Answers device queries (u6-u9) |
No | No | Yes * |
| Colours + attributes (bold, dim, underline, reverse) |
None | 16-colour | 256-colour |
In-line editing: cursor left/right, erase-to-EOL (cub/cuf/el) |
No | Yes | Yes |
| Named keys: arrows, Home/End, function keys |
No | Yes | Yes |
| In the base terminfo db - resolves on any host, incl. over ssh |
Yes | No (local) | Yes |
* TUI mode advertises the full entry on
purpose - a full-screen program needs cursor addressing - and is kept safe NOT by withholding
capabilities but by interpreting every escape into a confined
pyte screen grid where each glyph is neutralised. A capability it advertises
is one the renderer contains, not a hole.
The progression is the whole design: dumb
strips everything for maximum portability; secure-terminal keeps colour and line
editing while still refusing the full-screen and probe capabilities CLI mode cannot safely draw;
xterm-256color restores the full set for TUI mode, where the confined grid - not the
terminfo - is what keeps it safe. That is why a shell you ssh into uses TUI's portable
xterm-256color, while a local CLI shell uses secure-terminal. Either
way, safety rests on the renderer, never on TERM.
Isn't a custom TERM name a fingerprint? Only
a weak one, and not a property worth claiming. A remote host is told the string
"secure-terminal", but terminals are identified far more reliably by behaviour - how they
answer device queries (DA/DSR), their size, their quirks - than by a TERM value that
many emulators share anyway. If anything CLI mode is harder to probe: it answers no
queries at all (the u6-u9 capabilities are cancelled and every escape is
stripped). So the honest cost of the custom entry is not fingerprinting - it is
compatibility: a remote host has no secure-terminal terminfo, so a curses
program there sees an unknown terminal. That is the reason to ssh in TUI mode, whose
xterm-256color every host already has.
Does the richer entry widen the attack surface for
hostile DATA? No. Malicious output - a log full of embedded escapes that you
cat - emits raw bytes WITHOUT consulting terminfo, so it can send the exact same
sequences whichever entry is advertised; a richer TERM hands it nothing. And the
neutralising renderer never reads TERM at all (its only environment read is
NO_COLOR): it strips or contains the same fixed set of sequences regardless. So
cat hostile.log renders byte-for-byte identically under secure-terminal
and under dumb - the OSC 0 title hijack stripped, the stuck colour and
the DEC line-drawing shift neutralised to plain text. The terminfo entry only changes what
well-behaved programs choose to emit; it grants hostile data no extra reach.