使用 Roo 在 Spring MVC 中防止批量分配 [英] Prevent mass assignment in Spring MVC with Roo
问题描述
我正在与 Spring Roo 开始一个新项目.我发现它生成的 MVC 控制器容易受到批量分配的影响.我想知道是否有一种标准方法可以只允许更新某些字段.我正在考虑使用@InitBinder,但我不知道这是否是最好的方法.
I am starting a new project with Spring Roo. I have found that the MVC controllers that it generates are vulnerable to mass assignment. I wonder if there is a standard way to allow only certain fields from being updated. I am thinking about using @InitBinder, but I don't know if it is the best approach.
我的印象是,我所知道的大多数 Java EE 框架都忽略了这个问题和 CSRF 预防.更糟糕的是,这些漏洞甚至经常出现在他们自己的示例代码中.
I have the impression that this issue and CSRF prevention are overlooked in most of the Java EE frameworks that I know. Even worse, these vulnerabilities are often found even in their own sample code.
旁注:我已经知道 HDIV,但除了 CSRF 预防之外,我不想丑化"我的漂亮 REST URL.
Side note: I already know HDIV, but I don't want to "uglify" my nice REST URLs except for CSRF prevention.
推荐答案
这个问题没有很好的解决方案,选项:
There is no nice solution to this problem, options:
- 创建仅包含表单内容字段的表单或 DTO 对象(但这不适用于 spring roo)
- 使用对象的2个实例,表单实例和数据库实例,然后只将表单页面中的字段从表单实例复制到数据库实例
这里的这篇文章可以用来帮助解决批量分配问题:http://blog.42.nl/articles/利用-the-spring-mvc-3.1-handlermethodargumentresolver-interface/
This article here could be used to help solve the mass assignment problem: http://blog.42.nl/articles/leveraging-the-spring-mvc-3.1-handlermethodargumentresolver-interface/
这篇关于使用 Roo 在 Spring MVC 中防止批量分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!