TYPO3 Fluid viewhelper f:security.nonce 不生成随机数

问题描述 投票:0回答:1
在 TYPO3 12.4.13 中使用 CSP 指令时,我偶然发现了一个奇怪的问题。为了运行内联脚本,我使用 TYPO3 扩展特定方法为 script-src 指令定义了一个随机数值。在我的流体模板中,我使用 f:security.nonce() viewhelper 来生成正确的随机数值。但是,在某些情况下,viewhelper 不会生成随机数值。

以下是这些案例的一些示例。请注意,额外的 f:secity.nonce() viewhelper 仅用于测试目的。

在这种情况下,viewhelper 可以正常工作:

{f:security.nonce()} <!-- Outputs hash 0NnkfpY8... --> <script nonce="{f:security.nonce()}"> let map; async function initMap() { // Map map = new Map(document.getElementById("map"), {}); } initMap(); </script>
但是当向 

zoom: 14,

 对象添加类似 
Map
 的内容时,viewhelper 不会生成任何内容:

{f:security.nonce()} <!-- Outputs {f:security.nonce()} --> <script nonce="{f:security.nonce()}"> let map; async function initMap() { // Map map = new Map(document.getElementById("map"), { zoom: 14, }); } initMap(); </script>

这是另一个例子:
viewhelper 像这样工作:
{f:security.nonce()} <!-- Outputs hash 0NnkfpY8... --> <script nonce="{f:security.nonce()}"> let map; async function initMap() { // Set map constants const centerPosition = { lat: xxx, lng: xxx }, mapStyle = "xxxxxx"; const markerPosition = centerPosition; } initMap(); </script>
但是像这样它不会:

{f:security.nonce()} <!-- Outputs {f:security.nonce()} --> <script nonce="{f:security.nonce()}"> let map; async function initMap() { // Set map constants const centerPosition = { lat: xxx, lng: xxx }, mapStyle = "xxxxxx", markerPosition = centerPosition; } initMap(); </script>
    
typo3 fluid view-helpers
1个回答
0
投票
我对 Typo3 12.4.14 也有同样的问题。以下代码位于扩展模板中,只是为了执行一些简单的 javascript。

第一个示例有效,第二个示例无效。唯一的区别是删除了 console.log()。

这有效:

<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true" lang=""> <!-- Hello World {f:security.nonce()} --> <script nonce="{f:security.nonce()}"> (function () { const allSelectBoxes = document.querySelectorAll("select.bb-select.placeholder"); for (let item of allSelectBoxes) { item.addEventListener("change", function (event) { console.log("Hello World: {f:security.nonce()}"); if (this.selectedIndex === 0) { this.classList.add("placeholder-shown"); } else { this.classList.remove("placeholder-shown"); } }); const event = new Event('change'); item.dispatchEvent(event); } })(); </script> </html>
工作示例生成的 HTML:

<!-- Hello World _cEsvhNVZ6OgiKM8NI6L0u1sKYZKmOQxm4tf6O3f-eH00FmmvLue_g --> <script nonce="_cEsvhNVZ6OgiKM8NI6L0u1sKYZKmOQxm4tf6O3f-eH00FmmvLue_g"> (function () { const allSelectBoxes = document.querySelectorAll("select.bb-select.placeholder"); for (let item of allSelectBoxes) { item.addEventListener("change", function (event) { console.log("Hello World: _cEsvhNVZ6OgiKM8NI6L0u1sKYZKmOQxm4tf6O3f-eH00FmmvLue_g"); if (this.selectedIndex === 0) { this.classList.add("placeholder-shown"); } else { this.classList.remove("placeholder-shown"); } }); const event = new Event('change'); item.dispatchEvent(event); } })(); </script>
这不起作用,因为我删除了第 8 行 console.log("Hello World:)

<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true" lang=""> <!-- Hello World {f:security.nonce()} --> <script nonce="{f:security.nonce()}"> (function () { const allSelectBoxes = document.querySelectorAll("select.bb-select.placeholder"); for (let item of allSelectBoxes) { item.addEventListener("change", function (event) { if (this.selectedIndex === 0) { this.classList.add("placeholder-shown"); } else { this.classList.remove("placeholder-shown"); } }); const event = new Event('change'); item.dispatchEvent(event); } })(); </script> </html>
生成的不起作用示例的 HTML:

<!-- Hello World {f:security.nonce()} --> <script nonce="{f:security.nonce()}"> (function () { const allSelectBoxes = document.querySelectorAll("select.bb-select.placeholder"); for (let item of allSelectBoxes) { item.addEventListener("change", function (event) { if (this.selectedIndex === 0) { this.classList.add("placeholder-shown"); } else { this.classList.remove("placeholder-shown"); } }); const event = new Event('change'); item.dispatchEvent(event); } })(); </script>
    
© www.soinside.com 2019 - 2024. All rights reserved.