ajax – @InitBinder与@RequestBody在Spring 3.2.4中转义XSS
我在我的方法中有一个@RequestBody注释参数,如下所示:
@RequestMapping(value = "/courses/{courseId}/{name}/comment", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
public @ResponseBody CommentContainer addComment(@PathVariable Long courseId,
@ActiveAccount Account currentUser,
@Valid @RequestBody AddCommentForm form,
BindingResult formBinding,
HttpServletRequest request) throws RequestValidationException {
.....
}
然后我在同一个控制器中有一个@InitBinder注释方法:
@InitBinder
public void initBinder(WebDataBinder dataBinder) {
dataBinder.registerCustomEditor(AddCommentForm.class, new StringEscapeEditor());
}
我的StringEscapeEditor没有运行.但我的initBinder方法是.所以它没有将我的表单映射到转义编辑器.这似乎是在阅读这个帖子后(@InitBinder不支持@RequestMapping):
spring mvc @InitBinder is not called when processing ajax request
我测试了映射@PathVariable字符串,然后我的编辑器工作.
这在我的应用程序中是一个大问题,因为我的大多数绑定都是使用@RequestBody完成的,如果我可以应用一些自定义绑定,它会很棒.
解决这个问题最常用的方法是什么?并且为了脚本攻击而逃避我的输入数据.