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

1.8.13: page load broken with 'self' content security policy (Ace2Editor.init() error event while waiting for load event) #4975

Closed
dvzrv opened this issue Mar 25, 2021 · 31 comments · Fixed by #5124

Comments

@dvzrv
Copy link

dvzrv commented Mar 25, 2021

Describe the bug
After updating from 1.8.12 to 1.8.13 (no plugins, plain packaged version that I provide in the AUR), I get the following on loading any pad:

An error occurred

Please press and hold Ctrl and press F5 to reload this page

If the problem persists, please send this error message to your webmaster:
ErrorId: Hlk02KxskYcOry455748
Unhandled Promise rejection
URL: https://my-pad.tld/p/test
UserAgent: Mozilla/5.0 (X11; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0
Ace2Editor.init() error event while waiting for load event
at https://my-pad.tld/javascripts/lib/ep_etherpad-lite/static/js/pad.js?callback=require.define&v=580f7db7 at line 49

Reloading the page doe not fix the issue.

To Reproduce
Steps to reproduce the behavior:

  1. Go to any pad
  2. See error

Expected behavior
pad loads normally

Screenshots
screenshot-2021-03-25_20-28-38_blur

Server (please complete the following information):

  • Etherpad version: 1.8.13
  • OS: Arch Linux
  • Node.js version (node --version): v15.12.0
  • npm version (npm --version): 7.7.4

Desktop (please complete the following information):

  • OS: Arch Linux
  • Browser: Firefox
  • Version: 87.0

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Downgrading to 1.8.12 fixes the issue.

The PKGBUILD that creates the package can be found here: https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=etherpad-lite

@webzwo0i
Copy link
Member

works for me on ff 87.0/node 15.12.0/npm 7.7.4

Do you see any other errors in developer console when this happens?

@flotho
Copy link

flotho commented Apr 23, 2021

same issue with a reverse proxy and authenticatication in the proxy.
without the authentication in the proxy then it's working

@webzwo0i
Copy link
Member

Interesting! Would be cool to get this fixed.
Can you provide steps to replicate? Do you mean https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authenticate ?

@flotho
Copy link

flotho commented Apr 24, 2021

maybe related to #4820

@flotho
Copy link

flotho commented Apr 30, 2021

same issue with a reverse proxy and authenticatication in the proxy.
without the authentication in the proxy then it's working

my bad, failed with or without reverse proxy.

@flotho
Copy link

flotho commented Apr 30, 2021

$ node -v
v14.16.1
[etherpad@pad etherpad-lite]$ npm -v
6.14.12

here are the result :

client - i.niceSelect is not a function -- {
  errorId: 'NFBK9QbSxcFYsReiQBpX',
  type: 'Unhandled Promise rejection',
  msg: 'i.niceSelect is not a function',
  url: 'http://10.0.199.7:9001/p/atelierdev-connecteur-odoo',
  source: 'http://10.0.199.7:9001/static/js/require-kernel.js?v=83aad60f line 226 > Function',
  linenumber: 71,
  userAgent: 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0',
  stack: 'ep_webpack/static/dist/js/index-13b609ac302aec3ed7e9.js/module.exports</</t.postAceInit@http://10.0.199.7:9001/static/js/require-kernel.js?v=83aad60f line 226 > Function:71:18211\n' +
    'callHookFnAsync/<@http://10.0.199.7:9001/javascripts/lib/ep_etherpad-lite/static/js/ace2_common.js?callback=require.define&v=83aad60f:12958:18\n' +
    'callHookFnAsync@http://10.0.199.7:9001/javascripts/lib/ep_etherpad-lite/static/js/ace2_common.js?callback=require.define&v=83aad60f:12921:16\n' +
    'ep_etherpad-lite/static/js/pluginfw/hooks.js/exports.aCallAll/results<@http://10.0.199.7:9001/javascripts/lib/ep_etherpad-lite/static/js/ace2_common.js?callback=require.define&v=83aad60f:13036:54\n' +
    'ep_etherpad-lite/static/js/pluginfw/hooks.js/exports.aCallAll@http://10.0.199.7:9001/javascripts/lib/ep_etherpad-lite/static/js/ace2_common.js?callback=require.define&v=83aad60f:13036:13\n' +
    'postAceInit@http://10.0.199.7:9001/javascripts/lib/ep_etherpad-lite/static/js/pad.js?callback=require.define&v=83aad60f:500:13\n'
}

and same thing with node 16 and npm 7.10

@webzwo0i
Copy link
Member

webzwo0i commented Apr 30, 2021

Can you post a list of your installed plugins+version please.

@flotho
Copy link

flotho commented Apr 30, 2021

I can, but actually i restarted from a fresh install.
and now everything is running perfectly with either FF or chrome.
Here is the final conf :

Numéro de version: 1.8.13

Dernière version disponible: 1.8.13

Git sha: 5db0c8d
Greffons installés

ep_colibris_full_width
ep_etherpad-lite
ep_disable_chat
ep_font_size
ep_headings2
ep_adminpads2
ep_headerauth
ep_embedded_hyperlinks2
ep_themes
ep_table_of_contents
ep_list_pads
ep_image_upload

Parties installées

ep_image_upload/ep_image_upload
ep_list_pads/ep_list_pads
ep_table_of_contents/ep_table_of_contents
ep_themes/ep_themes
ep_embedded_hyperlinks2/main
ep_headerauth/ep_headerauth
ep_adminpads2/ep_adminpads2
ep_headings2/main
ep_font_size/main
ep_disable_chat/ep_disable_chat
ep_etherpad-lite/openapi
ep_etherpad-lite/adminsettings
ep_etherpad-lite/adminplugins
ep_etherpad-lite/admin
ep_etherpad-lite/tests
ep_etherpad-lite/socketio
ep_etherpad-lite/errorhandling
ep_etherpad-lite/importexport
ep_etherpad-lite/apicalls
ep_etherpad-lite/webaccess
ep_etherpad-lite/padreadonly
ep_etherpad-lite/padurlsanitize
ep_etherpad-lite/specialpages
ep_etherpad-lite/i18n
ep_etherpad-lite/stats
ep_etherpad-lite/static
ep_etherpad-lite/express
ep_etherpad-lite/Minify
ep_etherpad-lite/DB
ep_colibris_full_width/ep_colibris_full_width

Crochets installés
Crochets côté serveur

authenticate:

ep_headerauth:

    ep_headerauth:
        ep_headerauth 

ccRegisterBlockElements:

ep_image_upload:

    ep_image_upload:
        ep_image_upload/static/js/contentCollection 

clientVars:

ep_image_upload:

    ep_image_upload:
        ep_image_upload/index 

ep_themes:

    ep_themes:
        ep_themes/index:clientVars 

collectContentImage:

ep_image_upload:

    ep_image_upload:
        ep_image_upload/static/js/contentCollection 

collectContentPost:

ep_headings2:

    main:
        ep_headings2/static/js/shared 

ep_image_upload:

    ep_image_upload:
        ep_image_upload/static/js/contentCollection 

collectContentPre:

ep_font_size:

    main:
        ep_font_size/static/js/shared 

ep_headings2:

    main:
        ep_headings2/static/js/shared 

ep_image_upload:

    ep_image_upload:
        ep_image_upload/static/js/contentCollection 

createServer:

ep_etherpad-lite:

    express:
        ep_etherpad-lite/node/hooks/express 

eejsBlock_adminMenu:

ep_adminpads2:

    ep_adminpads2:
        ep_adminpads2 

eejsBlock_body:

ep_image_upload:

    ep_image_upload:
        ep_image_upload/index 

eejsBlock_dd_format:

ep_font_size:

    main:
        ep_font_size/index 

eejsBlock_dd_view:

ep_table_of_contents:

    ep_table_of_contents:
        ep_table_of_contents/index 

eejsBlock_editbarMenuLeft:

ep_embedded_hyperlinks2:

    main:
        ep_embedded_hyperlinks2/index 

ep_font_size:

    main:
        ep_font_size/index 

ep_headings2:

    main:
        ep_headings2/index 

ep_image_upload:

    ep_image_upload:
        ep_image_upload/editbar 

eejsBlock_editorContainerBox:

ep_embedded_hyperlinks2:

    main:
        ep_embedded_hyperlinks2/index 

ep_table_of_contents:

    ep_table_of_contents:
        ep_table_of_contents/index 

eejsBlock_indexWrapper:

ep_list_pads:

    ep_list_pads:
        ep_list_pads/index 

eejsBlock_mySettings:

ep_colibris_full_width:

    ep_colibris_full_width:
        ep_colibris_full_width/pad 

ep_table_of_contents:

    ep_table_of_contents:
        ep_table_of_contents/index 

eejsBlock_mySettings.dropdowns:

ep_themes:

    ep_themes:
        ep_themes/index:eejsBlock_mySettings_dropdowns 

eejsBlock_scripts:

ep_table_of_contents:

    ep_table_of_contents:
        ep_table_of_contents/index 

ep_themes:

    ep_themes:
        ep_themes/index:eejsBlock_scripts 

eejsBlock_styles:

ep_disable_chat:

    ep_disable_chat:
        ep_disable_chat/disable_chat:eejsBlock_styles 

ep_image_upload:

    ep_image_upload:
        ep_image_upload/index 

ep_table_of_contents:

    ep_table_of_contents:
        ep_table_of_contents/index 

exportHtmlAdditionalTagsWithData:

ep_font_size:

    main:
        ep_font_size/exportHTML 

expressCloseServer:

ep_etherpad-lite:

    socketio:
        ep_etherpad-lite/node/hooks/express/socketio 

expressConfigure:

ep_etherpad-lite:

    webaccess:
        ep_etherpad-lite/node/hooks/express/webaccess 

ep_image_upload:

    ep_image_upload:
        ep_image_upload/index 

expressCreateServer:

ep_adminpads2:

    ep_adminpads2:
        ep_adminpads2 

ep_etherpad-lite:

    admin:
        ep_etherpad-lite/node/hooks/express/admin
    adminplugins:
        ep_etherpad-lite/node/hooks/express/adminplugins
    adminsettings:
        ep_etherpad-lite/node/hooks/express/adminsettings
    apicalls:
        ep_etherpad-lite/node/hooks/express/apicalls
    errorhandling:
        ep_etherpad-lite/node/hooks/express/errorhandling
    i18n:
        ep_etherpad-lite/node/hooks/i18n
    importexport:
        ep_etherpad-lite/node/hooks/express/importexport
    openapi:
        ep_etherpad-lite/node/hooks/express/openapi
    padreadonly:
        ep_etherpad-lite/node/hooks/express/padreadonly
    padurlsanitize:
        ep_etherpad-lite/node/hooks/express/padurlsanitize
    socketio:
        ep_etherpad-lite/node/hooks/express/socketio
    specialpages:
        ep_etherpad-lite/node/hooks/express/specialpages
    static:
        ep_etherpad-lite/node/hooks/express/static
    tests:
        ep_etherpad-lite/node/hooks/express/tests 

ep_list_pads:

    ep_list_pads:
        ep_list_pads/index:registerRoute 

getLineHTMLForExport:

ep_font_size:

    main:
        ep_font_size/exportHTML 

ep_headings2:

    main:
        ep_headings2/index 

ep_image_upload:

    ep_image_upload:
        ep_image_upload/exportHTML 

handleMessage:

ep_headerauth:

    ep_headerauth:
        ep_headerauth 

loadSettings:

ep_headerauth:

    ep_headerauth:
        ep_headerauth 

ep_image_upload:

    ep_image_upload:
        ep_image_upload/settings 

padCreate:

ep_adminpads2:

    ep_adminpads2:
        ep_adminpads2 

padInitToolbar:

ep_font_size:

    main:
        ep_font_size/index 

padRemove:

ep_adminpads2:

    ep_adminpads2:
        ep_adminpads2 

restartServer:

ep_etherpad-lite:

    express:
        ep_etherpad-lite/node/hooks/express 

shutdown:

ep_etherpad-lite:

    DB:
        ep_etherpad-lite/node/db/DB
    express:
        ep_etherpad-lite/node/hooks/express
    Minify:
        ep_etherpad-lite/node/utils/Minify
    stats:
        ep_etherpad-lite/node/stats 

socketio:

ep_adminpads2:

    ep_adminpads2:
        ep_adminpads2 

ep_etherpad-lite:

    adminplugins:
        ep_etherpad-lite/node/hooks/express/adminplugins
    adminsettings:
        ep_etherpad-lite/node/hooks/express/adminsettings
    socketio:
        ep_etherpad-lite/node/handler/PadMessageHandler 

stylesForExport:

ep_font_size:

    main:
        ep_font_size/exportHTML 

ep_headings2:

    main:
        ep_headings2/index 

ep_image_upload:

    ep_image_upload:
        ep_image_upload/exportHTML 

Crochets côté client

aceAttribsToClasses:

ep_embedded_hyperlinks2:

    main:
        ep_embedded_hyperlinks2/static/js/index 

ep_font_size:

    main:
        ep_font_size/static/js/index 

ep_headings2:

    main:
        ep_headings2/static/js/index 

ep_image_upload:

    ep_image_upload:
        ep_image_upload/static/js/clientHooks 

aceCreateDomLine:

ep_embedded_hyperlinks2:

    main:
        ep_embedded_hyperlinks2/static/js/index 

ep_font_size:

    main:
        ep_font_size/static/js/index 

aceDomLineProcessLineAttributes:

ep_headings2:

    main:
        ep_headings2/static/js/index 

ep_image_upload:

    ep_image_upload:
        ep_image_upload/static/js/clientHooks 

aceEditEvent:

ep_headings2:

    main:
        ep_headings2/static/js/index 

ep_table_of_contents:

    ep_table_of_contents:
        ep_table_of_contents/static/js/aceEditEvent:aceEditEvent 

aceEditorCSS:

ep_colibris_full_width:

    ep_colibris_full_width:
        ep_colibris_full_width/static/js/colibris_full_width 

ep_font_size:

    main:
        ep_font_size/static/js/index 

ep_headings2:

    main:
        ep_headings2/static/js/index 

ep_image_upload:

    ep_image_upload:
        ep_image_upload/static/js/clientHooks 

aceInitialized:

ep_embedded_hyperlinks2:

    main:
        ep_embedded_hyperlinks2/static/js/index 

ep_font_size:

    main:
        ep_font_size/static/js/index 

ep_headings2:

    main:
        ep_headings2/static/js/index 

ep_image_upload:

    ep_image_upload:
        ep_image_upload/static/js/clientHooks 

ep_themes:

    ep_themes:
        ep_themes/static/js/init 

aceRegisterBlockElements:

ep_headings2:

    main:
        ep_headings2/static/js/index 

ep_image_upload:

    ep_image_upload:
        ep_image_upload/static/js/clientHooks 

ccRegisterBlockElements:

ep_image_upload:

    ep_image_upload:
        ep_image_upload/static/js/contentCollection 

collectContentImage:

ep_image_upload:

    ep_image_upload:
        ep_image_upload/static/js/contentCollection 

collectContentPost:

ep_image_upload:

    ep_image_upload:
        ep_image_upload/static/js/contentCollection 

collectContentPre:

ep_embedded_hyperlinks2:

    main:
        ep_embedded_hyperlinks2/static/js/index 

ep_font_size:

    main:
        ep_font_size/static/js/shared 

ep_headings2:

    main:
        ep_headings2/static/js/shared 

ep_image_upload:

    ep_image_upload:
        ep_image_upload/static/js/contentCollection 

handleClientMessage_ACCEPT_COMMIT:

ep_table_of_contents:

    ep_table_of_contents:
        ep_table_of_contents/static/js/aceEditEvent:aceEditEvent 

handleClientMessage_NEW_CHANGES:

ep_table_of_contents:

    ep_table_of_contents:
        ep_table_of_contents/static/js/aceEditEvent:aceEditEvent 

postAceInit:

ep_colibris_full_width:

    ep_colibris_full_width:
        ep_colibris_full_width/static/js/colibris_full_width 

ep_embedded_hyperlinks2:

    main:
        ep_embedded_hyperlinks2/static/js/index 

ep_font_size:

    main:
        ep_font_size/static/js/index 

ep_headings2:

    main:
        ep_headings2/static/js/index 

ep_table_of_contents:

    ep_table_of_contents:
        ep_table_of_contents/static/js/postAceInit:postAceInit 

postToolbarInit:

ep_font_size:

    main:
        ep_font_size/static/js/index 

ep_image_upload:

    ep_image_upload:
        ep_image_upload/static/js/toolbar 

It works behind an apache RP with authentication through apereo CAS.

"requireAuthentication": true,
"trustProxy": true,
"headerauth": {
"username_header": "x-authenticated-user",
"displayname_header": "x-authenticated-name"
},

hope it can help.

I still have something that bothering me.
When I'm looged in ssh with the etherpad user, the npm version is 7.10 but in the logs, it use the 6.4.x release.
Any idea where it could come from?

Regards

@larskasper
Copy link

Could it be that the server (a proxy server like nginx) is setting a Content-Security-Policy header (CSP)?

That can be checked in the server configuration, or in a web browser’s inspector/developer tools (in Firefox for example: ToolsWeb DeveloperWeb Console, then expanding the GET requests and looking for Response Headers; in that console you also see the errors if something is blocked by CSP), or in a tool like curl (curl -isS https://pad.example/p/test | grep -i content-security-policy).

I noticed the mentioned error message and non-working pads with Etherpad Lite version 1.8.13 when in the proxying nginx a Content-Security-Policy was set. The error was gone when the Content-Security-Policy was not set (or a permissive one like add_header Content-Security-Policy "default-src https: 'unsafe-eval' 'unsafe-inline'"; was set, which still blocks some content), or when Etherpad Lite version 1.8.12 was used (with a Content-Security-Policy).

@nuxi
Copy link

nuxi commented Jun 25, 2021

I just upgraded etherpad from 1.8.6 to 1.8.13 and hit this issue.

Previously something like this worked just fine default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' data:; connect-src 'self'; img-src 'self' https: data:; media-src 'self' https:; frame-src 'self'; frame-ancestors 'self'; form-action 'self'

Now 'self' no longer seems to match requests eventhough they are going to the same host, with the same port, and the same scheme. To get it working again I had to explicitly add the host to default-src, script-src, style-src, and connect-src. This shouldn't be necessary, 'self' should have covered this case. I don't know why it suddenly isn't after an upgrade.

@nuxi
Copy link

nuxi commented Jun 25, 2021

I was able to bisect it, 'self' worked in the CSP up until 40448606

@rhansen
Copy link
Member

rhansen commented Jul 3, 2021

Do all browsers behave the same? This looks like a browser bug to me (see MDN), but I don't know enough about CSP to be sure.

@nuxi
Copy link

nuxi commented Jul 5, 2021

I see the problem in Firefox 89 and I do not see it in Chromium 90.

I'm just running 1.8.12 instead for now.

@webzwo0i
Copy link
Member

webzwo0i commented Jul 6, 2021

Not a browser bug, but non-perfect spec, see w3c/webappsec-csp#459 and https://bugzilla.mozilla.org/show_bug.cgi?id=1567970

:-(

@dvzrv
Copy link
Author

dvzrv commented Jul 15, 2021

I can confirm that adding the host to the CSP header explicitly "fixes" this. However, given that 40448606 broke this, I'd appreciate this being fixed in etherpad, rather than waiting for mozilla to investigate this.

@rhansen
Copy link
Member

rhansen commented Jul 19, 2021

Reverting commit 4044860 is not feasible, and it's unclear to me how to work around this in Firefox. If someone can figure out an approach that works I'd be happy to apply it.

@rhansen
Copy link
Member

rhansen commented Jul 20, 2021

Not a browser bug, but non-perfect spec, see w3c/webappsec-csp#459 and https://bugzilla.mozilla.org/show_bug.cgi?id=1567970

Those links are talking about an unrelated issue. (Those are regarding the meaning of "self" when used in a <meta http-equiv="Content-Security-Policy" content="..."> tag in a child srcdoc iframe.)

I did some more digging and to me the standard is clear on this topic:

Whenever a user agent creates an iframe srcdoc document in a browsing context nested in the protected resource, if the user agent is enforcing any policies for the protected resource, the user agent MUST enforce those policies on the iframe srcdoc document as well.

So I really think this is a Firefox bug, not a flaw in the standard. I couldn't find it reported anywhere so I did some more investigation and this bug only happens when you have nested srcdoc iframes (<iframe srcdoc="..."> inside another <iframe srcdoc="...">). I suspect that not many applications have nested iframes like this, which is probably why I couldn't find any existing reports. I filed a new bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1721296

@webzwo0i
Copy link
Member

webzwo0i commented Jul 20, 2021

I really appreciate the effort @rhansen!
The part of the spec you cited seems to be clear and iirc I also saw it failing on the inner, not the outer iframe. I found https://wpt.fyi/results/content-security-policy/meta/sandbox-iframe.html?label=experimental&label=master&aligned which seem to fail the same way we saw here (although it's meta tag + img-src and sandbox)

In CSP3 draft the cited paragraph doesn't appear anymore and there is:

Note: This is needed to facilitate the 'self' checks of local scheme documents/workers that have inherited their policy but have an opaque origin. Most of the time this will simply be the environment settings object’s origin.

Our inner iframe has an opaque origin (srcdoc) and has inherited it's policy (from the outer iframe where it was dynamically generated), but not sure it is a "local scheme document".
Also:

Note: We compare against the fallback base URL in order to deal correctly with things like an iframe srcdoc Document which has been sandboxed into an opaque origin.

(we don't use sandbox or explicit base hrefs, though)

Because of this I thought CSP3 is way more clear than CSP2 (although the above paragraphs might not apply to our use case), then I found https://github.com/antosart/policy-container-explained which I probably misinterpreted (it seems to talk about unifying the different approaches to inheritance across all the various policies out there).

Indeed I run the tests with meta tags - ignoring that policies won't be enforced to anything above the meta tag. Besides that my understanding is that it shouldn't make a difference if CSP is applied via header or meta?!

So thanks again for filling the bug report and let's see if we get some insights from mozilla. @dvzrv Is anything blocking you from not using self? Maybe we can add some other code that helps setting a correct header not using "self"? It was a bigger effort to get to where we are now regarding page load, so reverting the commit is not an option imo.

@rhansen Just in case: What do you think, if we'd try to remove iframes entirely from Etherpad? There was a PoC PR some time ago. IMO, this would be a clever step for the future, but I'm not sure if it'll break anything badly.

@webzwo0i
Copy link
Member

It's getting even weirder: (After adding require-kernel/ace2inner/ace2common to script tags instead dynamically adding from parent) Adding any or both of innerFrame.csp and outerFrame.csp with a value of script-src 'self' fails in Chromium, too (Firefox does not support csp attributes of iframes yet).

Adding <meta http-equiv="Content-Security-Policy" content="script-src ip:port"> to the inner iframe's head element when setting srcdoc will make it work in Chromium, as does script-src 'self'. So what's the difference setting this via csp attribute or meta element?

webzwo0i added a commit that referenced this issue Jul 20, 2021
Using srcdoc, especially with multiple nested iframes, seems to be
problematic when using `self` in CSP policies.
@webzwo0i
Copy link
Member

@rhansen If you'd accept something like #5124 (probably with relative links) I can add some more templating, so that it would reduce the amount of script/style injections etc in ace.js. I expect a large amount of code in ace.js to become obsolete after doing this.

At least this seems to fix the CSP issue, as it works with self now, provided the corresponding headers are set when serving aceInner/aceOuter (probably also works when only sending the headers with pad.html - I didn't test this)

I must admit, I don't remember why we used srcdoc in the first place

@webzwo0i
Copy link
Member

@dvzrv Just for completeness, can you test if #5124 fixes the problem for you?

@rhansen
Copy link
Member

rhansen commented Jul 26, 2021

Our inner iframe has an opaque origin (srcdoc)

The CSP3 draft is difficult to read, but I think it's more subtle than that.

The location for srcdoc iframes is a URL with a local scheme (about:srcdoc). A URL's origin is opaque if it has a local scheme. However, if I understand correctly, srcdoc iframes get a copy of their parent's policy, so 'self' checks in srcdoc iframes should be against the origin used by the parent (which is not opaque), not the srcdoc iframe's origin (which is opaque). (If the srcdoc iframes were sandboxed then the 'self' checks would be against an opaque origin.)

(I'm far from an expert on this topic, so my understanding of the spec could be wrong.)

What do you think, if we'd try to remove iframes entirely from Etherpad?

In the long run I think it would result in better code, but I think it would take a considerable amount of effort. In particular, we would need to figure out a way to migrate plugins (example).

So what's the difference setting this via csp attribute or meta element?

Setting CSP in a srcdoc iframe's meta tag is the topic of the bugs you originally linked. In other words, the standard is not clear. (If you set the CSP in the meta tags for the top-level frame (src/templates/pad.html) then it should behave as expected.)

@rhansen If you'd accept something like #5124 (probably with relative links) I can add some more templating, so that it would reduce the amount of script/style injections etc in ace.js. I expect a large amount of code in ace.js to become obsolete after doing this.

I like the approach in PR #5124. For the first iteration I would prefer to serve empty HTML and leave the code in ace.js mostly untouched (only change srcdoc='<!DOCTYPE html>' to src='../_empty.html'). In a later PR we can convert the ace.js iframe element creation code into served HTML.

@rhansen rhansen changed the title 1.8.13: page load broken (Ace2Editor.init() error event while waiting for load event) 1.8.13: page load broken with 'self' content security policy (Ace2Editor.init() error event while waiting for load event) Jul 26, 2021
rhansen pushed a commit that referenced this issue Jul 29, 2021
Using srcdoc, especially with multiple nested iframes, seems to be
problematic when using `self` in CSP policies.
rhansen pushed a commit that referenced this issue Jul 30, 2021
Using srcdoc, especially with multiple nested iframes, seems to be
problematic when using `self` in CSP policies.
@dessalines
Copy link

dessalines commented Apr 18, 2024

This is also happening with the newest version of etherpad. Works in FF, but fails in chrome / android.

Please add a DISABLE_CSP so that we can bypass this.

@SamTV12345 SamTV12345 reopened this Apr 18, 2024
@SamTV12345
Copy link
Member

So as an Option? As far as I can see this can imply security issues with XSS. I'll have a look how to implement that.

@dessalines
Copy link

Yep, that'd be best. Only add the CSP headers if DISABLE_CSP=false , which could be the default.

@SamTV12345
Copy link
Member

Alright. I'll try that. If it's simply another header being conditionally added it should not be too hard.

@SamTV12345
Copy link
Member

Yep, that'd be best. Only add the CSP headers if DISABLE_CSP=false , which could be the default.

Found the plugin suitable for this: #4031

@webzwo0i
Copy link
Member

@dessalines
Please provide steps to replicate

@webzwo0i
Copy link
Member

For me it works on Chrome (123) and Chrome on Andoid (119?).

In case you cannot provide working steps to replicate, can you try to git bisect the commit that introduced the regression?

Disabling seems like a workaround, but the underlying problem needs to be identified.

@dessalines
Copy link

Whoa, I waited a few hours and the issue cleared up. Not even restarting my machines, or reinstalling etherpad worked at first. Sorry about that yall.

It probably had to do with not enabling TRUST_PROXY, then some weird system-caching.

@SamTV12345
Copy link
Member

Great that this is resolved now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants