Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Comments on Safe handling and display of untrusted data in the terminal

Post

Safe handling and display of untrusted data in the terminal

+5
−0

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.)?

History

1 comment thread

Recovery (1 comment)
Recovery
GeraldS‭ wrote 6 months ago · edited 6 months ago

Obviously not an answer, but it might be useful for readers to know that a terminal session can usually be recovered by blindly typing reset followed by the enter/return key into the terminal after the output has been wrecked by control codes from binary data.