CollaboraOnline / online

Collabora Online is a collaborative online office suite based on LibreOffice technology. This is also the source for the Collabora Office apps for iOS and Android.
https://collaboraonline.com
Other
1.79k stars 685 forks source link

Support sandboxed iframe #8921

Open DeepDiver1975 opened 5 months ago

DeepDiver1975 commented 5 months ago

Describe the Bug

Collabora Online cannot be used inside a sandboxed iframe because collabora tries to access the parent document. See screenshots below for further details

Steps to Reproduce

  1. load Collabora in <iframe sandbox="allow-scripts">
  2. see it failing

Expected Behavior

Shall load

Actual Behavior

Does not load

Screenshots

image image

Desktop

Additional Context

ocis docker setup as per https://github.com/owncloud/ocis/tree/master/deployments/examples/ocis_wopi

meven commented 5 months ago

Regarding allow-same-origin, it is required currently for:

For localization this could be changed. For localstorage, this would require to read and pass to the host window those settings.

Using sandbox="allow-same-origin allow-scripts" is already an isolation improvement, but COOL does not work properly in those conditions. I am looking into it.

meven commented 5 months ago

Regarding allow-same-origin, it is required currently for:

* localstorage accessing and reading, user's settings

* localization is loaded using XHtmlRequests

For localization this could be changed. For localstorage, this would require to read and pass to the host window those settings.

Using sandbox="allow-same-origin allow-scripts" is already an isolation improvement, but COOL does not work properly in those conditions. I am looking into it.

Using allow-scripts allow-same-origin allow-downloads allow-popups for sandbox allows CODE to work properly.

DeepDiver1975 commented 5 months ago

Yes - but from a security perspective I don't want to grant an application allow-same-origin.

Under the assumption that the ifamed application is compromised by a vulnerability if can leave the iframe and also attack the parent application. Any interaction between these two applications should happen using Window.postMessage() - see https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

meven commented 5 months ago

Yes - but from a security perspective I don't want to grant an application allow-same-origin.

I understand, and Collabora Online could support it with some efforts. allow-same-origin is a lot more restrictive that just communicating with the parent frame.

Collabora Online already uses only postMessage to communicate with the parent frame. But without allow-same-origin, indeed Collabora Online is a potential attack vector.

meven commented 4 months ago

An option on your end, is to host Collabora-online on a host with a different domain (or just port difference). That would restrict access from the iframe to the parent application, making it a cross-domain iframe. That might not be easy to accommodate on your end though.

mmeeks commented 4 months ago

Question is - where are we not using post-message? there is that frame resizing thing; @meven do we have a short list of things to fix that get this wrong ? =)

meven commented 4 months ago

Question is - where are we not using post-message? there is that frame resizing thing; @meven do we have a short list of things to fix that get this wrong ? =)

I have a POC branch of Collabora Online with localstorage turned off, localization off and without the resize iframe that runs in Firefox (but not chrome) and firefox has presentation restriction (even with a allow-presentation).

meven commented 4 months ago

The _fileDownloader iframe could also be replaced either with a "<a download" or window.downloads.

meven commented 4 months ago

I have tested the clipboard and it seems affected for complex pasting (but that might another issue).

I have made a branch that has a few features turned off as a baseline to test COOL with sandbox="allow-scripts allow-presentation allow-downloads allow-popups" :

https://github.com/meven/cool-online/tree/meven/iframe-sandboxed

The missing features are the welcome window, l18n, presenting in window is broken and full-screen not-working.

Apart from that, I haven't noticed any problems.

Some compatibility changes are missing (replacing im Map.js the _fileDownloader and _resizeDetector by other means (a download, and ResizeObserver ) that can already be made in master.

mmeeks commented 4 months ago

Getting a new server-side setting storage API implemented is really a larger task if we can't use the browser setting storage; this is a longer term task I think.

mmeeks commented 2 months ago
  1. The presentation window is being re-worked to not run JS in a downloaded SVG - which should help there.

  2. I believe @vmiklos just re-wrote the clipboard code to do its downloading where necessary server-to-server which should help make those large-inter-document pastes work even in this case.

The welcome window - I believe we can proxy that via online reasonably easily as we currently do for the LOK image; there should be no need for the client to go to a different server for that; so we're making progress :-)

DeepDiver1975 commented 2 months ago

Hey - any news on this topic? Anything I can help out? ;-) THX a lot

mmeeks commented 2 months ago

Sure - good to check - a quick update:

So; TODO:

Thanks!