我在普惠制中有以下几点:
<%=model.something%>
在Config.groovy,我有:
grails {
views {
gsp {
encoding = 'UTF-8'
htmlcodec = 'xml' // use xml escaping instead of HTML4 escaping
codecs {
expression = 'html' // escapes values inside null
scriptlet = 'html' // escapes output from scriptlets in GSPs
taglib = 'html' // escapes output from taglibs
staticparts = 'none' // escapes output from static template parts
}
}
// escapes all not-encoded output at final stage of outputting
filteringCodecForContentType {
//'text/html' = 'html'
}
}
}
但是,当我在控制器中设置model.something =“警告(‘某事’)”并呈现视图时,我会得到警告框。
如果我将其改为使用${model.something},则它似乎正确地转义。但我希望安全的一面,并确保脚本输出也是编码的。我是否需要配置中的其他内容才能做到这一点?
发布于 2015-09-03 09:48:41
<%=%>
表单并不意味着任何转义。只需使用${}
。
默认情况下,${..}块中的变量不会转义,因此变量字符串中的任何HTML都将直接呈现给页面。为了减少跨站点脚本(XSS)攻击的风险,可以使用grails.views.default.codec设置启用自动HTML转义。
注意,关于<%=%>
没有什么可说的。按照我自己的实践,我确认设置不影响JSP标记(您可能需要将一些事情不转义)。
https://stackoverflow.com/questions/19325530
复制相似问题