With Firefox on X11, any page can pastejack you anytime (middle button paste)
openwall.com
openwall.com
Having a single mouse button (that often has other functionality like autoscroll in Firefox) cause text highlighted in another app to paste in the focused app is super unintuitive to me, and caused a few significant annoyances unintentionally pasting secrets or private messages in the wrong place before I got rid of it.
I do agree that overloading the button is terrible. I like the scroll wheel but wish there was a separate middle button. And I loathe middle button auto scroll, I regard it as a useless, user hostile feature.
That’s why I felt it was a bad default.
"Other than that, Mrs. Lincoln, how was the play?"
I didn't know wayland doesn't support that either, one more thing to add to the list of things it doesn't support like screenshots, xclip, mouse/keyboard automation, etc...
It's fine to dislikes it; everyone dislikes some features (e.g. personally I really dislike autoscroll). The thing is that it's not "unexpected" because it's been like this for >30 years, since the 80s. Nor is there anything wrong with it: it's just something you can like or dislike.
Or to put it in another way: if I wanted my Unix system to behave like Windows or macOS then I'd be using Windows or macOS.
Can't talk about the others as I don't use them.
https://github.com/bugaevc/wl-clipboard
$ cat ~/bin/clip
#!/bin/sh
if [[ -z $WAYLAND_DISPLAY ]]; then
xclip -selection clipboard
else
wl-copy
fiGrim for screenshots, slurp for selection (similar to maim). wl-clipboard works like xclip with its wl-copy and wl-paste commands, I use it extensively in scripts. There is ydotool (not to be confused with xdotool) for kb/m automation. Highlight + middle click paste also works as expected and I use that many times a day. Primary selection is also available to wl-clipboard with a -p arg for both copy and paste.
t. actual daily Sway user for several years now
It's insane to me how much misinformation is spread about Wayland by people who just don't even try it. I guess people want to hate it.
I suspect it didn't work at one point and then people ditched it and have that as their memory. I tried to switch to sway, a bunch of stuff didn't work like I expected and I just switched back to i3, this was probably 3-4 years ago at this point.
I assume it's probably gotten better, so I don't go around commenting. But I fully believe people did try it and it didn't work for them (at some point) and they just ditched it.
Then I try to middle click autoscroll in discord or something (which works in windows!) and I’ll paste in information that I don’t intend to.
This is the first I’m hearing about Wayland fixing this. Maybe I’ll give Wayland yet another try soon.
You can fix this in the latest working firefox version with `about:config > middlemouse.paste = false` (I found this by browsing through about:config, so I'm not sure if it's decumented anywhere), but I'm not sure if that still works in the enshittified versions.
(It doesn't prevent selected text from being middle-pasted into other applications, but all my other disrupted-by-paste applications explicitly don't support middle-click-to-paste (in several cases because I deliberately wrote them that way), so I haven't gotten around to fixing that part yet.)
But this “feature” is enabled globally across XServer and is so deeply engrained that there is no global off switch. I must find workarounds for every application in order to make my middle mouse click function as I would expect.
For an OS where everything else is so customizable this baffles me.
I so frequently encounter problems where I proofread something (or my compiler finds it for me) and I find weird words or sentence fragments that I inserted on accident while navigating a document.
We're having a conversation in this thread about whether or not the feature is good, but it shouldn't matter. People who like the behavior and people who don't should be able to live side by side, without one affecting the other. The issue is that the feature should not be forced.
Also, "no modes" is both a question of personal preference and a sliding scale. Input-has-focus is a mode, too, but getting rid of that would be an obvious mistake.
I hardly ever touch the mouse, but if I am using it then I'm most likely copying and pasting. Don't make that difficult.
All trackpads I've tried support middle click via a three-finger tap.
https://www.notebookcheck.net/Review-HP-ZBook-15-Workstation...
I disabled tap to click and all gestures except two finger scrolling.
https://superuser.com/questions/90257/what-is-the-difference...
https://www.gnu.org/software/emacs/manual/html_node/emacs/Se...
When I'm reading a long article, my usual strategy is to middle-click and then move the mouse to a position that causes the page to move in time with my reading speed. The continuous movement is a lot easier for my eyes to track than occasional bursts of scrolling, and I can tweak the scroll speed by subtly adjusting the mouse position. It's a bit like cruise control for scrolling.
I'm not saying you ought to use it, but you're decrying it as "not user-friendly" and "not needed" when what you really mean is "I don't like it" and "I don't use it".
Windows now has clipboard history by pasting with Win+V, having the best of both worlds.
I'm sorry you can't adapt, but honesty no one cares =)
What’s problematic with the Firefox behavior is that content gets copied (pasted) that wasn’t selected by the user.
The patch here would not help security at all. Only using control-x control-e before pasting (so that it comes into a real editor, not directly in the terminal) can help.
Invisible text can add to what you selected, but it can’t replace it.
There’s also an argument to be made that invisible text shouldn’t be copied, though that’s harder to define precisely (you don’t want to copy “display: none”, but you want to copy scrolled-out content).
Also in Mintty: https://mintty.github.io/mintty.1.html#%03Text%20selection,%...
Of course that means I also don't have a horse in the "What should middle click do race".
You can bind a keyboard shortcut to a script that copies the primary to clipboard, then can use ctrl-v. Most apps also bind shift-insert to paste the paste buffer, so I bind shift-delete to this script, then to paste the primary it's just shift-delete then shift-insert. Here's the "script":
xsel -p | xsel -i -bTried a few solutions but they didn't work on Wayland (as most of them were xinput hacks).
I didn't experience such accidental pastes when I had Windows installed.
In places where this doesn't work, clipboard history is an okay replacement (if you need multiple things "transported").
Copying should always be deliberate, not something that blasts out your clipboard when you click in the wrong place and select something unintentionally. And middle click is for opening tabs.
This isn't helped by the fact that the mainstream desktop OSes don't have proper clipboard managers bundled by default. Accidentally copying something isn't as big a deal when you have the most recent 200 items you've copied in an easily searchable widget.
Poor API design and the inability for APIs like the clipboard to evolve are part of the reason why desktop Linux's security keeps falling behind other operating systems.
Either way, I'm pretty sure it could be added if someone cared enough, e.g. by adding a new target.
It just seems to me that if someone is able to access your clipboard history you've lost already, and the entire feature seems more of a convenience thing than a security thing.
Win32: https://learn.microsoft.com/en-us/windows/win32/dataxchg/cli...
WinRT: https://learn.microsoft.com/en-us/uwp/api/windows.applicatio...
>Either way, I'm pretty sure it could be added if someone cared enough
That's the problem. Ironically, not enough people care about improving the security and privacy of desktop Linux.
>It just seems to me that if someone is able to access your clipboard history you've lost already
Do you not see how it could be problematic if sensitive things were logged and persisted to disk?
Edit: Some clipboard managers on Linux do have an undocumented way to do this by adding an additional format to what's being copied with a MIME type set to x-kde-passwordManagerHint and data set to "secret".
And your link just shows some programmatic access? How do I access that as a user when I press Ctrl+C? I suppose it's "useful" for things like password managers, but since anything can read the clipboard anyway it's a very limited protection. If something is so sensitive that you're using that special programmatic way of storing it then you should be using the clipboard but an actually secure mechanism.
Learning that you can middle click on the back/forward/refresh buttons to open the previous/next/current page (respectively) in a new tab was a game changer for me
However it's a nightmare when you use a mix of OSes every day as I do :(
He was copying a listing all of the executables in various locations on the machine he'd created using ls -l, into a text document (logged in as root). Unfortunately, he accidentally middle-clicked while moving the mouse to the text editor, and it pasted everything into the shell.
Since it was mostly symlinks in the standard /bin /sbin /usr/bin /usr/sbin etc, the shell dutifully redirected garbage into each destination binary, rendering the OS unusable.
One must be root to be able to do that.
Most Wayland compositors will refuse clipboard requests from unfocused clients.
Additionally, the Wayland protocol carries an event identifier, so that the compositor can tie the clipboard request to a pointer/keyboard/touch event and take a better decision. (This metadata is missing for X11 clients, of course.)
That's actually not the case. There's a serial number that the client provides when they want to set the selection (that is, cut/copy)[0][1], but nothing when a client requests a paste[2][3].
I always thought this is weird; while yes, it's nice to prevent random applications from spuriously taking over as the source of the clipboard/primary, I think it's much more important to have a mechanism to reduce the risk of a client pasting without permission.
[0] https://wayland.app/protocols/wayland#wl_data_device:request... (regular clipboard)
[1] https://wayland.app/protocols/primary-selection-unstable-v1#... (primary selection)
[2] https://wayland.app/protocols/wayland#wl_data_offer:request:... (regular clipboard)
[3] https://wayland.app/protocols/primary-selection-unstable-v1#... (primary selection)
I also misinterpreted what this issue was about; my mental assumption of "pastejacking" is when a malicious app grabs the (possibly sensitive) clipboard contents without the user knowing about it (which the Wayland protocol doesn't protect against via a serial number in the request)... but that's the opposite of this issue. And you're right, in this case a compositor could absolutely reject Firefox's set_selection() request here since any serial passed to it would probably be out of date.
And correct me if I'm wrong, but IIRC wlroots does make an effort to check that the serial passed is current enough.
1) Beware! any site you visit can, via javascript, inject whatever it wants into your clipboard (write access)
2) Beware! any site you visit can, via javascript, do whatever it wants with your clipboard (READ and write access) <-- this would freak me out and require immediate opsec change on my part
3) some combination of the above.
4) something different.
I use exclusively Firefox (as opposed to any browser) and haven't touched wayland. I also only type on keyboards with a trackpoint and a middle click button, and have for the past few decades. Hence, I'm sure I make heavy use of all the various methods of accessing clipboards..
(I'm guessing it's closer to #1 than #2, I think I once saw a crypto address in my clipboard unexpectedly on a VM...)
Usually webpages cannot read the clipboard, and instead rely on the browser/os/whatever sending them its contents when the user ctrl+v or right-click-paste. It would then be received as a javascript event.
On Linux, there's the clipboard, which is the Ctrl+C/Ctrl+V that most people are familiar with.
There's also the "primary selection", which is the currently highlighted text. That selection can be pasted into a different app or text box with middle click. So you can really quickly do highlight, middle-click, highlight, middle click.
The primary selection is stored separately from the clipboard too, so it won't overwrite the contents of such.
But, because setting the primary selection is just selecting text, if JS selects text, then it sets the primary selection. Compare with the clipboard: JS cannot normally set the clipboard except in certain contexts (the OP goes into these).
(Well, technically, it doesn't actually "inject" anything, it just changes the selection, and arguably it's "working as intended").
To those wondering who would paste and execute without a second look, there are ways to hide text. You can also paste control characters, so if you pasted into vim the command would get executed without any visible feedback. Same could be true for emacs, someone who knows it better could pipe in.
Any time you run potentially malicious code (like clicking on a random link when you have javascript enabled) on the same computer as data you care about, you're taking a risk. Sandboxing is a compromise, but one that's usually worthwhile.
I believe Emacs differs in two relevant ways, both not technically inherent: command prefixes are by default non-printable, and it's relatively uncommon to run Emacs without GUI.
Just tried `echo -en '\x18\x03' | xclip`.
Emacs in the default GUI mode works as expected, just pastes ^X^C (that's two control characters, they are just rendered this way) into the buffer.
xfterm4 or gnome-terminal pastes Unicode Control Pictures [1] (TIL there's such a thing) ␘␃, the same in bash, cat or `emacs -nw`.
Finally, bash in xterm echoes the control characters raw, but Emacs once again manages to get ^X^C in the buffer.
This is a problem with web browsers. They shall not run untrusted code from the internet.
But we are now in the stage "oh, cool, i can access my USB from internet".
This is absolutely a bug, and almost certainly a security bug. If you consider pastejacking the clipboard within the threat model that you want to account for, selection-jacking like this is absolutely within it, as it's a superset in terms of bad behavior.
(… but browsers have long maligned the primary selection on Linux. Neither Firefox nor Chrome have behaved properly for a long time, so it's not really surprising that they don't wanna when it comes to this bug. The primary selection is incredibly useful, but unique to Linux and even there, poorly understood amongst its userbase due to being a bit tricky to discover.)
Not just browsers, users also rightfully malign the primary selection. I highlight text for all sorts of reasons (including because I already have something that I want to paste).
And a much worse attack exists: you copy e.g. shell code from the page, and instead of what you see, you paste something evil in your terminal.
Pages stealing your current middle-mouse-paste selection, however, only requires selecting text in another place, and it seems like the only way to defend against this is by not selecting text. Which, at least for me, is not really feasible.
cd /etc/portage/patches/www-client/firefox/
nano nomiddleclickhijack.patch
#paste patch, save
emerge -av firefoxSometimes you want some custom patches to suit your needs, then, well.. yeah, it takes some manual work.
EDIT: I thought the behavior was preserved for textareas, as the comment box here still copied on select. But it suddenly disabled it here too. Restarting the browser is probably a safe bet :)
Say you're about to copy a crypto wallet. You have it selected, and are about to press CTRL-C to copy it. It is entirely possible for malicious code to detect that. And, as it turns out, it's possible for it to change the selection to a different (invisible) string, right as you press CTRL-C.
There are even examples using terminal escape codes, to hide what happened.
https://www.reddit.com/r/privacy/comments/rv964x/comment/hr4...
A solution is bracketed paste[1] as mentioned in earlier comments[2], which would allow the user to examine a pasted command before running it.
and that editor should not be running "inside" a terminal
-- or rather I don't understand why those that like interacting with their editor via a terminal interface don't create a new protocol that doesn't have the warts and vulnerabilities the current ancient protocol has.
e.g. Vim creating their own protocol is rather pointless if no terminal implements it, and some terminal creating their own protocol is also rather pointless without application support.
Plus there's tons of software out there and it'll take a long time for it all to be rewritten, if that ever happens. e.g. X11 will still be around for a long time as well. So you will need to remain compatible with the current protocol even if you invent something new and better, and in that sense it doesn't really fix anything., at least not right now. It might fix stuff 15 years down the line, maybe, but in-between now and 15 years everything will be more complex by having two protocols.
And all things considered, it's not that bad, IMHO. There's the KiTTY Keyboard protocol to solve some obvious UX issues with keyboard handling, which is a clear improvement and motivation, whereas some exploit vectors that don't really see live exploits isn't really.
The hairiest Emacs Lisp code I know about is the code for responding to mouse actions, e.g., clicking and dragging, and most Vim users don't even want to use a pointing device to interact with Vim IIUC. (In contrast, 80% of Emacs users who responded to a survey do not interact with Emacs through a terminal interface.)
For example, the old scripting language Tcl has its own GUI toolkit named Tk that has a pretty good reputation.
>And all things considered, it's not that bad
It seems bad enough to me to be worth re-architecting.
But in a terminal all code runs in that terminal, and terminal programs don't "link against" a terminal in the same way that you do with a GUI toolkit. You need to implement a shared protocol on both ends.
So I suppose we're not very far from this not being a problem in general.
Though I understand this also works via control codes. I hope Tilix is smart enough to filter them out from the clipboard before doing this..
edit: I tested that case out, and it works. I suppose the protocol uses quoting.
But I don't recall Firefox ever being hardcore security and privacy (even though some of their techies are). For Mozilla, that's a fairly recent positioning that they're growing into.
Initially, there was competition to be the most popular browser.
But most of the history is a constant movement towards having the browser facilitate what companies wanted to do towards users (moving away from the "user agent" as an agent of the user).
In parallel, Google paying Mozilla for placement, and then possibly to keep a nominal competitor alive.
In recent years, Mozilla has been positioning itself as one of the champions for Internet freedom, and I assume that some of their people were that all along (e.g., the kind who could've gone to Google, but chose to work for much less money at Mozilla). Though I don't know how genuine that sentiment is from the top, when leadership draws huge compensation, for poor performance, while laying off techies. (Techies traditionally have lead Internet freedom, from the ground, up, and leadership might be better thought of as a humble support system for that.)
More on topic, this works fine within the trusted green zone of local desktop applications. but the browser is(or should be) a high security zone. with a really tricky security policy. which to paraphrase would be "Allow passing information to the rest of the os. but only as a result of a direct user request." You don't really want to disallow the browser to script selecting anything, this is useful for editors. but you probably want to maintain a flag on that selection as to if it was done by the user or not.
Well there is my useless pedantry for the day done. My apologies and thank you for letting me get that off my chest.
Lose selection === unable to copy. And it's at all times up to source app to decide what it will allow to be copied.
brave://settings/content/clipboardMost browser exploits are delivered by JavaScript, so the safest course of action is to use NoScript judiciously, run the browser in a VM, and pray.
https://unix.stackexchange.com/questions/24330/how-can-i-tur...
What sucks is I use middle click paste all the time so now I'll have to decide if I want to leave it disabled for potentially improving security.
I've also set dom.event.clipboardevents.enabled to false since I don't want websites messing with the clipboard.
I tried hard but could not find a relevant bug on Bugzilla, but that could be because security-related issues are typically kept under wraps until the details are safe to be publically revealed. At least that was the case for the one I submitted a few years ago; as the submitter, I can see it when I'm logged in, but it doesn't show up on anonymous searches.
If Mozilla's stance on this really is as described in the mailing list, I would very much like to add a dissenting opinion. This is clearly a security issue that needs addressing. If the clipboard buffer needs special protection, so does the primary selection buffer.
Whether most people like or dislike copy/pasting this way is irrelevant. Some people use it. The other browsers on X11 are properly protected. Even Edge on Linux gets it right. Firefox is the odd one out here and they should fix it.
Especially these days, where install instructions on web pages often look like this:
curl -o- https://example.com/trust/me/install.sh | sudo bash
EDIT: As per the author's GitHub issues, the bug report is indeed still hidden:https://bugzilla.mozilla.org/show_bug.cgi?id=1855345
https://github.com/turistu/odds-n-ends/issues/1#issuecomment...
What do you mean?
Arguably, it's "working as intended" because middle click is supposed to paste whatever is selected, and the JS did select some text. Fixing this in a way that won't cause UX regressions and can't be by-passed relatively easily might be rather tricky.
One possible approach could be to ignore selections made by JS (instead of directly by the user) for middle click paste. A more refined approach could also allow them when made by JS while handling a mouse click from the user.
You can consider that to be an acceptable trade-off, but it is a trade-off.
I would like to turn all that completely off.
> For firefox running in Wayland, `writeXPrimary()` will only succeed when the firefox window (the main window, not necessarily the tab the code runs in) has the focus. Otherwise the selection will be cleared. At first I assumed that this is something specific to the Wayland protocol, but that turned out to be utterly false; it's just some quirk, bug or "feature" specific to either firefox itself or GTK.
> But I think that's still bad enough, even if the page should take care to only set the selection when the main window has gained focus.
Edit: did y'all miss the smiley at the end of my comment?
I was not looking for this as a feature when I bought one a few years ago but it had them and it has proved the thing I like about the machine the most.
And it is the absolute most comfortable mouse I've ever used.
you already decided to hit enter while you are selection something, could be just a bit above your current cursor in the terminal
Gnome shell doesn't AFAIK.
It's an odd thing to protect from; any program that has access to the X11 clipboard is going to be able to run a process as the current user.
If I select some text and press Ctrl+C, it should copy the text I selected. The user intent is obvious. There's no excuse for the ability to hijack the clipboard to exist in the first place.
Web pages shouldn't be able to modify my selection. Why is there even an API for this?
The web ecosystem (including browsers) turned straight up malicious like 15 years ago, and users became nothing more than a product for everyone involved. That cancer has even metastasized and spread to the OS or even products that people pay thousands or tens of thousands of dollars for. I don't know how people who think that way can live with themselves.
To make “copy to clipboard” buttons possible.
On my phone, if I select text, my browser pops up a menu with "copy" as an option.
Why does a web page need to reinvent that wheel?
For the 1/10000000 case where it makes sense, how about a "X page wants to modify your clipboard" dialog? This has been a known security vulnerability for at least a decade.
Edit: actually, I just noticed that was a reply to selection, which makes even less sense. Just let the user select what they want.
The user tells their computer to do a simple thing, and the computer adversarially does not do that thing, and instead obeys someone else, intentionally. That should not happen.
If you went to a scissor factory and told them that their scissors were too sharp, they might at least think of doing a run of safety scissors. If you go to a tailor and suggest that, they will probably be confused and not very receptive.
Or if instead of things like the sawstop, we made power saws that sometimes just flip open the guard and swing the blade to toward the user. But there's a safety to prevent that, but it disengages whenever you start the saw, so you need to reengage it every time you cut something in-between starting the saw and actually cutting.
In a following snippet, the terminal scrolls 100 lines and prints no prompt, so a user is tempted to press Enter just to check what's going on. You can count this as a form of phishing, if you want.
open a new tab
type: about:config
Accept the prompt
type middlemouse.paste
change value “true” to “false” (double click or switch on the rightside)
restart firefox
--does this solve it?It's copy that's an exploit vector.
To disable it, set clipboard.autocopy to false.