Comments on Safe handling and display of untrusted data in the terminal
Post
Safe handling and display of untrusted data in the terminal
Suppose I have a binary file with some "readable" content in it that I want to display and inspect in the terminal. It's not a problem if cat produces a mess of strange symbols, but it could be a problem (or even a security risk) if the output contains, in particular, ANSI control codes. Maybe it just messes up the terminal (some of these issues are harder to recover from than others) but it can actually be malicious.
More generally, even something that I expect to be an ordinary "text file" might not be; sometimes one will have to deal with arbitrary, untrusted data. (Aside from the above terminal vulnerabilities, plain text can also exploit various quirks of Unicode to misrepresent what is written. This is especially important if, for example, I'm trying to audit a shell script before running it.)
Are there any standard tools that mitigate the risks of trying to display an arbitrary file in the terminal? What about paging the file (more, less etc.) or processing it to view partial contents (head, tail, cut etc.)?

1 comment thread