ams*_*ams 4 security xss spring-mvc jackson
跨站脚本备忘单有许多防止 XSS 攻击的规则。我想在我的 Web 应用程序中实现这些建议,该应用程序使用 Spring MVC + Jackson + JPA + Hibernate Bean Validation。作为示例,请考虑以下与我的应用程序中的代码类似的代码。
public class MessageJson {
@NotEmpty // Bean Validation annotation
private String title;
@NotEmpty
private String body;
// ... etc getters / setters
}
public class BolgPostController
{
@RequestMapping(value="messages",method=RequestMethod.POST)
public void createMessage(@Valid @RequestBody MessageJson message)
{
// **Question** How do I check that the message title and body don't contain
// nasty javascripts and other junk that should not be there?
// Call services to write data to the datababse
}
@RequestMapping(value="messages",method=RequestMethod.get)
public @ResponseBody List<MessageJson> createMessage()
{
// get data from the database
// **Question** How do I escape all the data in the list of MessageJson before
I send it back to the data.
}
}
Run Code Online (Sandbox Code Playgroud)
我可以看到以下方法来实施备忘单规则:
我正在寻找这三个选项中任何一个的 SpringMVC 的一些示例配置,并且优先选择选项 B 和 C。
setTitle()当读取 JSON 时,在属性(如属性)的 setter 中最容易做到这一点title。
或者,如果您正在考虑转义其他字符(例如,防止嵌入 HTML 标记),请查看此博客文章:使用 Jackson 在 JSON 中转义 HTML 字符。
| 归档时间: |
|
| 查看次数: |
11828 次 |
| 最近记录: |