From 2008cff999a1d6dd01199b6468c99e25265e72e4 Mon Sep 17 00:00:00 2001 From: "Gaetan Vanden Bergh (gavb)" Date: Fri, 28 Jul 2023 12:49:34 +0000 Subject: [PATCH] [FIX] web_editor: not access cssRules from other domains domain = host = hostname + port Cause: https://github.com/odoo/odoo/pull/125251 Steps to reproduce: - Add in the custom with a href's host different than the current database host - Open website - Edit it - Click on a block OR add a block and try to save Actual: - Infinite loading due to SecurityError on the cssRules fields Expected: - No infinite loading opw-3432734 opw-3438480 opw-3435892 opw-3371073 closes odoo/odoo#130151 X-original-commit: 8d550d5cc5f055a9de26e3b050550268710b1827 Signed-off-by: Benoit Socias (bso) --- addons/web_editor/static/src/js/editor/snippets.options.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index 54df499c5b0..26c19a6367c 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -7127,6 +7127,11 @@ registry.BackgroundShape = SnippetOptionWidget.extend({ this._lastShapePalette = palette; this._shapeBackgroundImagePerClass = {}; for (const styleSheet of this.$target[0].ownerDocument.styleSheets) { + if (styleSheet.href && new URL(styleSheet.href).host !== location.host) { + // In some browsers, if a stylesheet is loaded from a different domain + // accessing cssRules results in a SecurityError. + continue; + } for (const rule of [...styleSheet.cssRules]) { if (rule.selectorText && rule.selectorText.startsWith(".o_we_shape.")) { this._shapeBackgroundImagePerClass[rule.selectorText] = rule.style.backgroundImage;