Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
xterm, prevent pasting text by mistake
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
Leonardo.b
Apprentice
Apprentice


Joined: 10 Oct 2020
Posts: 297

PostPosted: Tue Dec 20, 2022 11:35 pm    Post subject: xterm, prevent pasting text by mistake Reply with quote

In xterm, I often triple-click by mistake, pasting whatever text I selected in some other X window, such that it gets executed.
Do you know a way to prevent this?
I think there should be an Xresource option or similar, but I fail to find it.
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Tue Dec 20, 2022 11:55 pm    Post subject: Reply with quote

Which shell do you use?

Probably not bash - because developers recently have changed the default to "do not execute pasted commands before an additional enter key was pressed."

EDIT: in bash, bracketed paste mode can be enabled / disabled with:
Code:
bind 'set enable-bracketed-paste on'
bind 'set enable-bracketed-paste off'
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21633

PostPosted: Wed Dec 21, 2022 1:40 am    Post subject: Reply with quote

I did not know how to prevent this. However, according to man xterm, you can configure the triple click behavior by setting the X resource on3Clicks.
man xterm:
               none
                  No selection action is associated with this resource.  Xterm
                  interprets it as the end of the list.  For example, you may
                  use it to disable triple (and higher) clicking by setting
                  on3Clicks to “none”.
Based on my own experience, and on my reading of the manual page, triple left click should select, not paste.
Back to top
View user's profile Send private message
Leonardo.b
Apprentice
Apprentice


Joined: 10 Oct 2020
Posts: 297

PostPosted: Wed Dec 21, 2022 11:58 am    Post subject: Reply with quote

Thanks for replies.

mike155, usually I use some Korn Shell variant for interactive usage. mksh.

Hu, sorry.
I meant mouse middle-button single click, or touchpad three-finger click. The normal way to paste selected text.

Code:
$ I pasted this paragraph by mistake.
I: command not found
$ And it is a multilne paragraph.
And: this command is not found too
$ Last line. Not executed until I presss enter.


I thought there is an xterm option meant exactly to prevent that.
Maybe I remember wrong.
I'll go back to this when I have more time, it's not super important anyway.
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Wed Dec 21, 2022 2:31 pm    Post subject: Reply with quote

I searched for "mksh" and "bracketed" at Google and Google found this thread: https://www.linux.org/threads/how-to-disable-highlighted-pasted-text-in-the-terminal.35449/post-139858.

According to #3, it helps to disable bracketed paste mode in /etc/inputrc.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21633

PostPosted: Wed Dec 21, 2022 4:24 pm    Post subject: Reply with quote

linux.org appears to be hiding behind CloudFlare and, at least for me, CloudFlare is broken at the moment:
Code:
www.linux.org needs to review the security of your connection before proceeding.
It claims it needs Javascript and cookies, and refuses to show the answer(s) you found. No amount of whitelisting or refreshing could get it to actually return the requested document.

For the benefit of future readers, could you quote inline the explanation? As I understood the relation of highlighting and bracketed paste:
  • Bracketed paste is older, and when enabled provides exactly the behavior that OP wants.
  • Highlighting pasted text is a recent change (in my opinion, regression). The regression-like aspect is that it highlights whatever is bracketed, and the highlight could only be disabled by disabling bracketed paste mode completely. An upcoming release of bash adds a separate preference allowing the user to have bracketed paste enabled, but highlighting disabled.
  • Bracketed paste is a readline feature. Shells which do not use readline may not support it.


Further reading in man xterm and searching for paste took me to this section:
Code:
   Selection Functions
...
       Pointer button two (usually middle)
            “types” (pastes) the text from the given selection, if any,
            otherwise from the cut buffer, inserting it as keyboard input:

                ~Ctrl ~Meta <Btn2Up>:insert-selection(SELECT, CUT_BUFFER0)
I suspect that by changing that binding to an xterm function other than insert-selection, one could disable middle-click paste.
Back to top
View user's profile Send private message
Leonardo.b
Apprentice
Apprentice


Joined: 10 Oct 2020
Posts: 297

PostPosted: Sat Jan 07, 2023 11:34 pm    Post subject: Reply with quote

Bracketed paste seems to be what I am looking for, as long as the shell supports it.

I don't want to disable paste button in xterm, because of I still want to paste in vi using the mouse/touchpad.

Thank you both, and forgive me for late replies, my life is a mess these days.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21633

PostPosted: Sun Jan 08, 2023 1:48 am    Post subject: Reply with quote

In my opinion, when pasting to Vim, you will get better results if you enable Vim's X support (even for console Vim), and use the * / + registers to access the X clipboard buffers, rather than directing xterm to paste your clipboard into Vim as keystrokes. If you don't want to use X bindings, such as with a Vim running on a remote system without X11 forwarding, setting the Vim option paste can be helpful to discourage Vim from applying special processing to the input.
Back to top
View user's profile Send private message
Leonardo.b
Apprentice
Apprentice


Joined: 10 Oct 2020
Posts: 297

PostPosted: Sun Jan 08, 2023 2:38 pm    Post subject: Reply with quote

From linux.org (I can access it from my mobile, CloudFlare insecurity checks take ~15s):
rado84 wrote:
Not long ago all terminals somehow got a new option for a pasted text to appear as if it was marked by the user to be copied. But that was very annoying for me, [...]

For the current terminal window (a temporary solution):
Code:
bind 'set enable-bracketed-paste off'

A permanent solution:
Code:
echo "set enable-bracketed-paste off" >> ~/.inputrc


Hu, that seems nice, I'll look into that.

Yet another thing on my TODO list is to learn screen/tmux. I know they support their own way to copy/paste.
Sadly, TODO list keeps growing, meanwhile time left keeps decreasing.
Back to top
View user's profile Send private message
Leonardo.b
Apprentice
Apprentice


Joined: 10 Oct 2020
Posts: 297

PostPosted: Tue Feb 28, 2023 5:36 pm    Post subject: Reply with quote

An interesting exploit I read today:
https://security.stackexchange.com/questions/39118/how-can-i-protect-myself-from-this-kind-of-clipboard-abuse

Quote:
Many websites use JavaScript or CSS to stealthily insert or replace text in the user's clipboard whenever they copy information from the page. As far as I know this is mostly used for advertising purposes, but PoC for exploits have been demonstrated.
[...]
Pasting in a term-based editor isn't safe either. Pasting Escthen :! can cause a running Vim instance to execute a shell command.


It looks like pasting inside a terminal is not only inconvenient, but also it is a security hazard.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21633

PostPosted: Tue Feb 28, 2023 6:56 pm    Post subject: Reply with quote

Yes, this is the value of bracketed-paste, which allows a consuming application to detect the boundaries of the paste and treat the entire thing as a literal. However, the exploit as described does not work for me:
Code:
$ xclip -o | xxd
00000000: 6162 631b 3a21 6563 686f 2046 6f6f       abc.:!echo Foo
I started a Vim, entered Insert mode, middle-clicked, and the paste came through safely. The Escape was lost, and all the rest was inserted as literal text.

The safe way to paste into a Vim though is to direct Vim to read the contents of the X clipboard directly, by using "*p to paste the selection or "+p to paste the clipboard.
Back to top
View user's profile Send private message
Leonardo.b
Apprentice
Apprentice


Joined: 10 Oct 2020
Posts: 297

PostPosted: Thu Mar 02, 2023 3:56 am    Post subject: Reply with quote

I followed your suggestion and compiled vim with X support.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum