Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do something about the clipboard on insecure domains and Firefox #1106

Closed
code-asher opened this issue Oct 24, 2019 · 40 comments
Closed

Do something about the clipboard on insecure domains and Firefox #1106

code-asher opened this issue Oct 24, 2019 · 40 comments
Labels
browser-firefox bug Something isn't working
Milestone

Comments

@code-asher
Copy link
Member

code-asher commented Oct 24, 2019

Current workarounds:

On Firefox you can use middle-mouse click or shift+insert (possibly depends on your OS). Pasting with the right-click menu will not work on Firefox but you can press shift+right click to get the native context menu and use that to paste. ctrl+v will work in the editor but not the terminal.

On Chrome ctrl+shift+v should work in the terminal and ctrl+v should work in the editor. If you use Chrome over a secure domain and accept the clipboard prompt then the right click menu to paste will work for the terminal but not the editor.


Summary:

Currently only native paste or the clipboard API will work so there are certain cases where pasting will not work with the keybinding you'd expect (ctrl+shift+v in the terminal) or with the right-click menu (see my comments below for details).


Original post:

Currently if you try to copy on an insecure domain you get "cannot read property writeText of undefined` because it's trying to access the clipboard which is undefined in insecure contexts.

We could fall back to copying using document.execCommand("copy") which I think is what the editor does. That seems to work fine.

For paste I believe the editor listens to the native paste command. That's not an option for the terminal because it requires we use the native keybinding (ctrl+v) and that has a different function in the terminal.

I've experimented with document.execCommand("paste") in the past but it didn't work so I assume this is why VS Code didn't use it here although perhaps more research is warranted here. That means our only option is the browser clipboard API which is only available in secure contexts.

Having only copy but not paste available on the terminal doesn't seem like a good solution so I think our best bet is to detect when the context is insecure and display a message describing the need to use https.

Service workers don't work in an insecure context either so maybe it would be a good idea to display a message when the browser loads as well just so people are aware they're accessing code-server in an insecure way and that things might be broken (as well as just generally dangerous).

While we're at it we could also implement the editor paste command using the clipboard API which would resolve #1105.

@sr229
Copy link
Contributor

sr229 commented Oct 25, 2019

document.copyText() seems to be the only way we can support HTTP clipboard access but I'm not really certain if WHATWG will still keep it up, and that'll be bad for localhost dev if they decide to axe it.

@code-asher
Copy link
Member Author

We can work around copying, it's the pasting that's a problem. :(

@frank-dspeed
Copy link

why is it so hard to generate a self signed cert for general development use and allow that in the browser via import? You do that once you can reuse the certs for your own dev projects always and its done where is the problem=?

@sr229
Copy link
Contributor

sr229 commented Oct 27, 2019

Not everyone has the expense to do that, please consider those implications and never assume people to do one thing and do it correctly. This is not open for debate per se.

@easychen
Copy link
Contributor

why is it so hard to generate a self signed cert for general development use and allow that in the browser via import? You do that once you can reuse the certs for your own dev projects always and its done where is the problem=?

Well, some cloud platforms set certificate as enterprise version paid function, so some personal small projects have no way to enable https.

@frank-dspeed
Copy link

@easychen show me a link to such a offer. In general you can always get public signed certs from letsencrypt and private once for your company via any PC in that company

@frank-dspeed
Copy link

frank-dspeed commented Oct 28, 2019

@easychen to make my point clear if your using http + auth or without it does not matter your working with clear text over many hops this is not acceptable in 2019 as you expose everything over the line.

Even More Clear

A Login / JWT Token in the http Header of every Request in Clear Text is like Opening it for the Internet. A Cookie makes not much diffrence

@oldrichsmejkal
Copy link

Is it really so hard to make copy-paste working in terminal even on not trusted connections?

Is confusing error message: "cannot read property writeText" really better than making it work (maybe with some warning about the certificate issue)?

It works in Jupyterlab terminal for example..
When you check number of issues related to this problem, you see that this is quite common/serious thing which kills usability for quite a number of people...

@easychen
Copy link
Contributor

easychen commented Oct 28, 2019

@easychen show me a link to such a offer. In general you can always get public signed certs from letsencrypt and private once for your company via any PC in that company

it's not the fee for the certs self , it's for uploading certs to your apps.
it's a PaaS platform such as Google App Engine so you can't config Apache/Nginx your self ...

https://www.sinacloud.com/index/price.html

Screen Shot 2019-10-28 at 3 19 31 PM

@easychen to make my point clear if your using http + auth or without it does not matter your working with clear text over many hops this is not acceptable in 2019 as you expose everything over the line.

Even More Clear

A Login / JWT Token in the http Header of every Request in Clear Text is like Opening it for the Internet. A Cookie makes not much diffrence

We DO login via https, but just use this for temp online sandbox under a separate subdomain for every users.

And not all cloud platform has api to upload the certs ...

@code-asher
Copy link
Member Author

If we really need to make the clipboard work on insecure domains the only thing we can do is allow the native keybindings through and listen to the paste event (as far as I'm aware; happy to be proven wrong though).

As long as the browser supports Ctrl+Shift+V for pasting then that will work since we can't use Ctrl/Cmd+v.

Chrome supports Ctrl+Shift+V everywhere while Firefox only supports it for contenteditable=true elements so that would have to be taken into consideration. I don't know about Safari.

Also note you can use Shift+Insert although this might depend on your OS.

This is probably a change that should be made upstream, though, rather than patched in code-server.

It would be wise to use SSL even for a temporary sandbox though, right?

@easychen
Copy link
Contributor

It would be wise to use SSL even for a temporary sandbox though, right?

We will when possible, it's not a tech problem but a financial one. Version 1 is good enough for us, great thanks for your excellent work.


For the pasting problem, I see it works ( cmd+v ) under insecurity domain, maybe I missing something?

the

code-server
Version: 1.39.2
Commit: d81d5f499f09bc887db2fb9bb35e0222bf48d80c
Date: 2019-10-24T21:52:45.195Z
Browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36

@code-asher
Copy link
Member Author

code-asher commented Oct 29, 2019

My guess is that cmd+v has no assignment in VS Code for the terminal (I thought it did but I must have been wrong) which allows it to perform a native paste instead. You could check by searching for "cmd+v" in the keyboard shortcuts.

That actually presents an interesting workaround. If you're using Chrome and Ctrl+Shift+V doesn't work you can open the keyboard shortcuts and assign the terminal paste keybinding to something obscure you won't use which allows Ctrl+Shift+V to perform a native paste instead.

@easychen
Copy link
Contributor

My guess is that cmd+v has no assignment in VS Code for the terminal (I thought it did but I must have been wrong) which allows it to perform a native paste instead. You could check by searching for "cmd+v" in the keyboard shortcuts.

image

You are right. So it seems pasting is not a problem now …

@code-asher
Copy link
Member Author

Neat! So for anyone else having the problem, currently the workaround is to search in the keyboard shortcuts for "workbench.action.terminal.paste" then remove the keybinding (Delete or right-click and click Remove Keybinding).

The long-term plan: when the clipboard API isn't available, don't bind those keys.

@frank-dspeed
Copy link

this is also the case in upstream microsoft/vscode#83595, microsoft/vscode#83598

@sr229
Copy link
Contributor

sr229 commented Oct 30, 2019

We'll wait for upstream fix and see what we can do.

@code-asher
Copy link
Member Author

Another note about this on Firefox. Firefox doesn't support the clipboard API at all apparently (at least not on websites) and it also doesn't bind Ctrl+Shift+V so the above workaround doesn't work. The only solution as far as I can tell is to use contenteditable=true on Firefox which makes Ctrl+Shift+V work.

So there's currently no workaround for Firefox and it won't work even in a secure context.

@code-asher
Copy link
Member Author

Oh actually as previously mentioned Shift+Insert is a workaround.

@frank-dspeed
Copy link

@code-asher the problem even exist in theia

@code-asher code-asher changed the title Do something about the clipboard on insecure domains Do something about the clipboard on insecure domains and Firefox Mar 9, 2020
@ViRb3
Copy link

ViRb3 commented Mar 13, 2020

Another workaround for Firefox: Shift + Right-click opens the context menu, and you can simply click paste. Middle-click did not work for me.

@nhooyr nhooyr removed the enhancement Some improvement that isn't a feature label Apr 16, 2020
@nhooyr
Copy link
Contributor

nhooyr commented May 27, 2020

From #1725

I think the move will be to always show the paste option but when it's clicked display a message describing why it won't work and possible solutions (i.e. switch to Chrome).

@LindsayWeir Not sure why it doesn't work on iPad, maybe the clipboard API isn't implemented there. We should show a message there as well @code-asher

@nhooyr nhooyr added this to the v3.5.0 milestone Jun 3, 2020
@nhooyr nhooyr self-assigned this Jun 3, 2020
@hgw77
Copy link

hgw77 commented Jun 22, 2020

I was updating from 3.2.0 to 3.4.1. When I use shift + right click I see now a different native context menu where I can bookmark or save the content. But no paste option is on that context menu. I guess on the older version the terminal was kind of textarea where the context menu shows me copy and paste option? So for me it is not possible to paste any content to the terminal :-(

@Heath123
Copy link

Is this just on Firefox? What about using the native context menu adding the VS Code ones with this? It would be slightly more cluttered and wouldn't fit the VS Code theme, but I think that's worth it (or it could be optional).

@Heath123
Copy link

Heath123 commented Jul 19, 2020

How it would look (for the terminal context menu items):
image

@hgw77
Copy link

hgw77 commented Jul 20, 2020

yes it is only a problem with firefox, on chrome it works very well. If I use the shift + righ click now it looks like the screenshot below. As you can see, there is no chance to paste anything.....

Capture

@Heath123
Copy link

yes it is only a problem with firefox, on chrome it works very well. If I use the shift + righ click now it looks like the screenshot below. As you can see, there is no chance to paste anything.....

You have to right click in the actual terminal, it looks like you're right-clicking on the right-click menu

@hgw77
Copy link

hgw77 commented Jul 20, 2020

that was a fast answer ;-)

I click on the terminal and select a text with shift + left click and than I use shift + right click to open the context menu. As you can see now the native context menu is rendered above the terminal context menu, that happens somtimes.

Anmerkung 2020-07-20 105225 PNG

@ohadbenita
Copy link

I have the same issue with Chrome, what's the workaround for it?

@nhooyr nhooyr removed their assignment Aug 25, 2020
@nhooyr nhooyr removed this from the v3.5.0 milestone Aug 25, 2020
@pcgeek86
Copy link

pcgeek86 commented Sep 3, 2020

SHIFT + INSERT works with Firefox on Windows 10 version 2004

@AlCalzone
Copy link

Can confirm, shift + insert also works for me in Firefox on Windows 7.

@tidux
Copy link

tidux commented Oct 14, 2020

Looking at Mozilla's developer documentation this seems related to an experimental Blink-only feature "ClipboardItem."

https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API

@noverby
Copy link

noverby commented Nov 12, 2020

I found a workaround for Firefox!

Just set dom.events.testing.asyncClipboard to true.

@Miguelklappes
Copy link

I found a workaround for Firefox!

Just set dom.events.testing.asyncClipboard to true.

THANK YOU SO MUCH!

@noverby
Copy link

noverby commented Mar 24, 2021

@Miguelklappes If you are not being sarcastic, why did you give my comment a thumbs down?

@Miguelklappes
Copy link

Miguelklappes commented Mar 24, 2021

@Miguelklappes If you are not being sarcastic, why did you give my comment a thumbs down?

By mistake!! I wasn't being sarcastic haha

@jsjoeio jsjoeio added this to the On Deck milestone Mar 24, 2021
@hgw77
Copy link

hgw77 commented Jun 22, 2021

hey it seems something changed? with the latest FF version (and Codeserver Version 3.10.1) I can copy paste (CTRL+C, CTRL+V)in the terminal? I am totally surprised ;-)

@jsjoeio
Copy link
Contributor

jsjoeio commented Jun 22, 2021

Oh really? Maybe something got fixed upstream. Thanks for the note @hgw77 😄

@stale
Copy link

stale bot commented Dec 19, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no activity occurs in the next 5 days.

@stale stale bot added the stale label Dec 19, 2021
@stale stale bot closed this as completed Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser-firefox bug Something isn't working
Projects
None yet
Development

No branches or pull requests