根据 documentation on XSS ,我在 application.conf 中添加了以下行
future.escapeInTemplates=true
在我的网络应用程序中,用户可以向页面添加评论。文本字段接受用户输入的文本并将其保存到数据库。我输入了以下行作为评论
<script> alert('hi') </script>
这会按原样保存在数据库中,并在浏览器中显示相同的内容。不会出现警报弹出窗口。这是否意味着 XSS 问题没有发生? 即使没有在 application.conf 中添加 escapeInTemplates=true ,程序也会给出相同的行为。
有一些警告 elsewhere关于将未经净化的 html 保存到数据库。那么,我应该使用 Jsoup 之类的东西来净化用户输入,然后再将其保存到数据库吗?
最佳答案
escapeInTemplate
不会阻止保存 html,它会在模板中渲染时对其进行转义。来自 Play Framework 1.2.4 docs :
Play’s template engine automatically escapes strings. If you really need to insert unescaped HTML in your templates, you can do so using the raw() Java extension on the string. But if the string comes from a user input, you need to make sure it is sanitized first.
所以当模板中显示html时,<SCRIPT>
标签被转义为
<SCRIPT>
关于java - playframework1.2.4中的XSS预防,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9925183/