批量分配的解决方案是什么:不安全的活页夹配置漏洞?

Bra*_*yes 3 java fortify

我在Java中有这个Controller:

@Controller
public class AuthenticationController extends AbstractController {

  @RequestMapping(value = Constantes.MAPPING_AUTH_BASE_ASP, method = { RequestMethod.POST })
  public String authenticate(@Valid ComunicationWithAspRequest comunicationWithAspRequest, BindingResult result,
      RedirectAttributes redirectAttributes, HttpSession sesion) throws Exception {
    ...
    ...
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)

当我在Fortify中扫描代码时,对象comunicationWithAspRequest会导致“批量分配:不安全的活页夹配置漏洞”。可以控制在绑定过程中使用哪些HTTP请求参数,而忽略哪些参数?

Ben*_*eng 5

您可以参考使用Roo在Spring MVC中阻止批量分配问题。

您可以使用Spring MVC提供的@InitBinder@InitBinder将为json和bean映射指定白名单。

根据我的经验,我使用@RequestBody进行自动绑定。我需要添加@JsonIgnore来指定不包含在映射中的属性。

SimpleController.java

@RequestMapping(value="/simple")
public String simple(@Valid @RequestBody User user){
   simpleService.doSomething();
}
Run Code Online (Sandbox Code Playgroud)

User.java

public class User{
   private String name;

   @JsonIgnore
   private String dummy;

   public void getName(){return name;}
   public void setName(name){this.name = name;}
   public void getDummy(){return dummy;}
   public void setDummy(dummy){this.dummy= dummy;}

}
Run Code Online (Sandbox Code Playgroud)