【问题标题】:How to use t3:// TypoLinks in TYPO3 HTML Content Elements without disabling `parseFunc.htmlSanitize` globally?如何在 TYPO3 HTML 内容元素中使用 t3:// TypoLinks 而无需全局禁用 `parseFunc.htmlSanitize`?
【发布时间】:2021-11-06 09:20:43
【问题描述】:

自从 2021 年 8 月发布阻止Cross-Site Scripting via Rich-Text Content 的安全补丁以来,我注意到 HTML 内容元素的输出在我们的项目中突然发生了变化。新引入的HTML Sanitizer 删除了一些标签属性和标签(当模板被修改以便t3:// 样式TypoLinks 得到渲染时)。

所以简单的overriding the default Html.html Fluid Template,将<f:format.raw> 更改为<f:format.html> 并添加如下示例中的html 解码已不再足够。

<f:section name="Main">
    <f:comment> We use this to render links and other stuff in html elements </f:comment>
    <f:format.htmlentitiesDecode>
        <f:format.html parseFuncTSPath="lib.parseFunc">
            {data.bodytext}
        </f:format.html>
    </f:format.htmlentitiesDecode>
</f:section>

防止更改 HTML 内容元素提供的 html 代码输出的最简单方法是通过将 lib.parseFunc.htmlSanitize = 0 添加到 TypoScript 配置来全局禁用清理程序,这并不理想。

我怎样才能只为此目的禁用parseFunc.htmlSanitize

或者是否有其他解决方案可以在 HTML 内容元素中呈现 TypoLinks?

注意:如果不覆盖 Html.html 模板,则无需禁用 HTML Sanitizer!

【问题讨论】:

  • 目前还没有解决方案,但也许可以查看forge.typo3.org/issues/95158,它提出了一个新的 VH 来仅呈现链接,但保留所有其他 HTML 不变/未解析
  • 要复制 TypoScript 块,请使用 lib.parseHtmlFunc &lt; lib.parseFunc - 因此使用运算符 &lt; 而不是 =(用于标量分配)
  • @OliverHader 哦,愚蠢的我。感谢您指出这一点,它成功了。我开始使用 =&lt; 的引用,就像在 docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/9.5.x/… 中描述的那样,它没有完成它的工作,然后以这个错误的 TypoScript 告终。我将在下面自己添加答案。谢谢。
  • @GeorgRinger 使用仅处理 t3:// TypoLinks 的新 ViewHelper 的想法会更好、更可靠,并且只需在模板中使用 &lt;f:format.links&gt;{data.bodytext}&lt;/f:format.links&gt; 即可降低复杂性。
  • @Ludwig 我们来了&lt;f:transform.html&gt;review.typo3.org/c/Packages/TYPO3.CMS/+/70977

标签: typo3 fluid-styled-content


【解决方案1】:

只需复制lib.parseFunc 并禁用此副本中的消毒剂。

lib.parseHtmlFunc < lib.parseFunc
lib.parseHtmlFunc.htmlSanitize = 0

然后在你的Html.html 模板中使用这个lib

<f:section name="Main">
    <f:comment> We use this to render links and other stuff in html elements </f:comment>
    <f:format.htmlentitiesDecode>
        <f:format.html parseFuncTSPath="lib.parseHtmlFunc">
            {data.bodytext}
        </f:format.html>
    </f:format.htmlentitiesDecode>
</f:section>

感谢@OliverHader 让我走上正轨。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-16
    • 1970-01-01
    相关资源
    最近更新 更多