【问题标题】:@spring.url macro is not getting HTML escaped@spring.url 宏没有转义 HTML
【发布时间】:2021-10-18 11:29:42
【问题描述】:

我正在使用 spring-boot + freemarker(标准初始化项目)。

我的 .ftlh 文件中有一行

<a href="<@spring.url '/${customer.email}' />"
           class="zenith-link"
           id="use-qr-link">${customer.email}
        </a>

但是当我将"&gt;&lt;script&gt;alert("Boo!")&lt;/script&gt; 作为客户电子邮件注入时,它不会被转义(因此我的应用存在 XSS 漏洞)

有什么方法可以将 HtmlEscape 设置为 true

【问题讨论】:

    标签: spring freemarker html-escape-characters


    【解决方案1】:

    我检查了源代码(https://github.com/spring-projects/spring-framework/blob/main/spring-webmvc/src/main/resources/org/springframework/web/servlet/view/freemarker/spring.ftl),不仅没有启用转义的选项,而且他们故意在那里禁用了转义(?no_esc):

    <#macro url relativeUrl extra...>
      <#if extra?? && extra?size!=0>
         ${springMacroRequestContext.getContextUrl(relativeUrl,extra)?no_esc}
      <#else>
         ${springMacroRequestContext.getContextUrl(relativeUrl)?no_esc}
      </#if>
    </#macro>
    

    我不知道为什么。此外,这个东西(连同那里的许多其他宏)应该是#function,而不是#macro。然后用户可以完全控制转义,或者他们想要使用结果。 (无论如何,查看源代码很明显,无论是谁做的,都没有投资了解模板语言。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-19
      • 2010-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-03
      相关资源
      最近更新 更多