Strip control characters from pasted text #307
No reviewers
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
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: dnkl/foot#307
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "selection-multiline-paste-fix"
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?
We used to replace
\r\n
with\n
. This PR changes that to instead use\r
. That is, we replace\r\n
and\n
with\r
.This PR also strips
\x1b
from pasted text, to prevent e.g. bracketed paste from being disabled by including the "bracketed paste" end sequence in the text being pasted.Closes #305
Closes #306
Tested working in
bash
.This is perhaps a separate issue, but I don't think this PR completely addresses the problem described by http://thejh.net/misc/website-terminal-copy-paste, unless bracketed paste is enabled. For example, if you start
foot dash
and paste the offending text, it still immediately runs the commands.xfce4-terminal
seems to "solve" this problem by prompting the user (see attached image) if the text contains newlines. Pasting text without newlines seems to work without any warning, since in that case it at least gives the user a chance to see the pasted text and choose whether or not to press Enter (or Ctrl+C).Tested and it fixes the second example on http://thejh.net/misc/website-terminal-copy-paste. Although @craigbarnes points out the problem is not completely fixed.
However, the first issue is not yet fixed. I think foot needs to handle more control sequences, like: https://security.stackexchange.com/questions/39118/how-can-i-protect-myself-from-this-kind-of-clipboard-abuse/52655#52655
And it also needs to send a BRACKETED_PASTE terminal mode to notify the application (this is most likely the issue I experienced; the multi-line issue was a red-herring since the bug specifically triggered for multi-line input).
@dnkl Do you think this will make it to a minor point release since it seems
security relevant? Specifically, the part about filtering control sequences.
Also, it might be useful to double-check xterm's current implementation in case anything else is missing for bracketed-paste.
The "problem" in this case is detecting malicious paste attacks. What he means is that filtering out
\E
does not prevent all the ways paste can be abused in a terminal.That would indeed take things further and prevent more attack vectors.
See #305 (comment). TL;DR this doesn't have anything to do with bracketed paste mode.
There was a short discussion on IRC about detecting multiline pastes in non bracketed paste mode, and asking the user for confirmation before allowing the paste:
https://freenode.logbot.info/foot-terminal/20210120#c6599846
Yes, I think we should look into filtering control sequences, and yes, that can likely be backported to a 1.6.x point release.
Detecting and asking for confirmation before pasting multiline text is out of scope for this PR, and maybe out of scope for a point release. But it is something that should eventually be fixed.
From what I can tell, XTerm strips all non-formatting C0 characters, and all C1 characters by default.
This list can be extended by setting
disallowedPasteControls
:But:
Also not sure what
ENT
is?Since foot doesn't support C1 controls, and since they may be part of UTF-8 sequences, we should leave those be.
As for the other, filtering non-formatting C0,
BS
,DEL
,HT
,EOT
,ESC
andNUL
should be ok, I think?68333948d7
to5318d27212
Updated to strip non-formatting C0,
BS
,HT
andDEL
.One difference between foot and XTerm is that XTerm strips non-formatting C0 (like foot), but replaces the remaining characters with a space. Furthermore, which additional characters (i.e. formatting C0 and "other" -
BS
,HT
andDEL
in our case) that should be replaced is configurable in XTerm.I'd rather not add configuration options unless there's an actual use case. But if there's a need for it, we can of course make it configurable in foot too.
The remaining question is whether to strip or replace with space? As mentioned above, XTerm strips non-formatting characters, but replaces the remaining ones. I guess the idea is that non-formatting characters can be stripped because they don't affect the resulting text? While formatting characters are replaced to indicate something was there?
Replace \r\n and \n with \r, and strip \e from pasted textto Strip control characters from pasted textReplaced by #312
Pull request closed