Confirm before pasting multi-line text in non-bracketed paste mode #308
Labels
No Label
bug
doc
duplicate
easy
enhancement
help wanted
invalid
not-a-bug
performance
question
refactor
regression
upstream
what do you think?
wiki
wontfix
No Milestone
No Assignees
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: dnkl/foot#308
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
Is this necessary in terminal emulator? Sounds like the task for a shell; for example, in bash:
It's not strictly "necessary", but the terminal is in a unique position to help prevent paste hijacking attacks in one central place, rather than hoping for every shell to do the right thing.
Even bash only just started enabling that option by default a few weeks ago, so it'll probably still be a couple of years before the benefits of it become widespread.
For context, I was referring to the problem described at http://thejh.net/misc/website-terminal-copy-paste, which was previously mentioned in #305.
Alarmingly, the second example sucessfully exploits input in Bash v5.1.4 with
enable-bracketed-paste
enabled./me votes for the feature with both hands!
PR #312 should have improved that case to some degree. Before that PR, the bracketed paste end delimiter in the copied text would cause the commands to be executed immediately upon pasting. With that PR applied, the text is now only pasted in place and you have to press Enter to run it (or ideally Ctrl+C to cancel).
I think this issue is more about improving the situation in shells that don't enable bracketed paste mode, since even just a newline character in the text is enough to cause commands to be immediately executed in that case.
Another idea for improvement here might be an option to completely ignore pastes containing bracketed delimiters, since it's highly likely to be a pastejacking attack and if it's a one-size-fits-all approach for targetting terminals with or without bracketed paste enabled, it'd prevent the attack in both cases.
Sounds like a good idea. Can't think of any situations where it would be wrong.
One thing that makes this issue a bit harder than what it appears at first sight, is the fact that pasted data is streamed to the client.
I.e. foot reads a chunk of text, decodes it, and writes it to the client. This means scanning the entire paste text isn't possible (using the current implementation anyway).
Ok, here is something interesting. In foot v1.6.2, the first example was unsuccessful. In v1.6.3, 2nd one appears to be mitigated:
...but 1st one now goes through:
Is there a regression by any chance?
@sv hmm, weird. Both work for me, in zsh-5.8 and bash-5.1.4, with foot-1.6.3-383-g79e054f.
Granted, that isn't 1.6.3, but I'm not aware of any changes since then that would affect pasting in any way.
Both fail or both succeed to read the
/etc/passwd
& show the "bad idea" message?@sv both "work", as in I can see the attempted "hack", and it fails to read
/etc/password
. Sorry for the confusion; it was early in the morning, before coffee ;)That's... Unexpected. First one clearly doesn't "work" for me on 1.6.2 and second on 1.6.3. Maybe cosmic rays flipping the memory bits or Debian-specific packaging of gnu-readline/bash/foot.
I just tried this again with fresh builds of 1.6.2 and 1.6.3, running
bash
as the shell. For me, the only combination that runs the commands on paste is the second attack with 1.6.2.@sv are you sure you're not doing something like connecting a 1.6.3
footclient
to a 1.6.2foot --server
? I've made that mistake more times than I care to admit.At least one data point that works for >1 person. 2nd attack with 1.6.2.
I'm reasonably certain this is not the case. 1.6.2 is now gone as Debian package wouldn't keep an old binary after upgrade/restart.
Anyway, I've just built
foot
fromc97e5da
and think I might be onto something.When testing performance-optimised, non-PGO build - both attacks are not successful on the first run, but subsequent paste successfully exploits input even after terminal reset.
Demo video:
Sorry, but I still cannot reproduce. Neither in bash nor zsh.
Hi,
Another place this feature is nice is when you're running TUI programs other than shells. When primary selection contains a lot of text, a stray middle-click can for instance dump a wall of text into an irc channel or a keyboard-driven application. Some irc clients detect and prevent this, but not all, and basically no mail clients (etc) do. So regardless of the shell paste mode, it would be nice to have a confirmation option for pasting multi-line text.