Skip to content

Commit d2a9e2f

Browse files
AC-11662 CSP - improve script rendering
1 parent 816a859 commit d2a9e2f

File tree

1 file changed

+38
-28
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/templates/stage

1 file changed

+38
-28
lines changed

app/code/Magento/PageBuilder/view/adminhtml/templates/stage/render.phtml

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,38 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/** @var \Magento\PageBuilder\Block\Adminhtml\Stage\Render $block */
7+
/** @var \Magento\PageBuilder\Block\Adminhtml\Stage\Render $block
8+
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
9+
*/
810
?>
9-
<script>
10-
<?php
11-
/**
12-
* Override the text! plugin within the iframe to ensure we can pipe any XHR requests through to the parent window
13-
* as the same origin policy will not allow us to load the templates within this iframe.
14-
*/
15-
?>
16-
require.config({
17-
'map': {
18-
'*': {
19-
'text': 'Magento_PageBuilder/js/master-format/render/requirejs/text',
20-
'Magento_PageBuilder/js/events': 'Magento_PageBuilder/js/master-format/render/events'
21-
}
22-
}
23-
});
2411

25-
<?php
26-
/**
27-
* To be able to override the text plugin we need the Magento template engine to be used, as the template engine
28-
* within lib has a dependency on the text! plugin we need to ensure we set the template engine before the
29-
* dependency blocks us. If we try to just override using the RequireJS config above our !text plugin will never
30-
* get overridden as our template engine cannot load.
31-
*/
32-
?>
12+
<?php
13+
/**
14+
* Override the text! plugin within the iframe to ensure we can pipe any XHR requests through to the parent window
15+
* as the same origin policy will not allow us to load the templates within this iframe.
16+
*/
17+
?>
18+
<?php
19+
$pageBuilderConfig = $block->getPageBuilderConfig();
20+
21+
$script = <<<SCRIPT
22+
require.config({
23+
'map': {
24+
'*': {
25+
'text': 'Magento_PageBuilder/js/master-format/render/requirejs/text',
26+
'Magento_PageBuilder/js/events': 'Magento_PageBuilder/js/master-format/render/events'
27+
}
28+
}
29+
});
30+
SCRIPT;
31+
32+
/**
33+
* To be able to override the text plugin we need the Magento template engine to be used, as the template engine
34+
* within lib has a dependency on the text! plugin we need to ensure we set the template engine before the
35+
* dependency blocks us. If we try to just override using the RequireJS config above our !text plugin will never
36+
* get overridden as our template engine cannot load.
37+
*/
38+
$script .= <<<SCRIPT
3339
require([
3440
'ko',
3541
'Magento_Ui/js/lib/knockout/template/engine'
@@ -39,10 +45,14 @@
3945
ko.uid = 0;
4046
ko.setTemplateEngine(templateEngine);
4147
});
42-
</script>
43-
<script>
48+
4449
require(['Magento_PageBuilder/js/master-format/render/frame'], function (listen) {
45-
listen(<?= /* @noEscape */ $block->getPageBuilderConfig(); ?>);
50+
listen(${$pageBuilderConfig});
4651
});
47-
</script>
52+
?>
53+
SCRIPT;
54+
55+
/* @noEscape */ $secureRenderer->renderTag('script', [], $script, false)
56+
?>
57+
4858
<div>Page Builder Render Frame</div>

0 commit comments

Comments
 (0)