【问题标题】:What is the solution for Mass Assignment: Insecure Binder Configuration Vulnerability?Mass Assignment: Insecure Binder Configuration Vulnerability 的解决方案是什么?
【发布时间】:2018-04-01 02:21:35
【问题描述】:

我有这个 Java 控制器:

@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 {
    ...
    ...
    ...
  }
}

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

【问题讨论】:

    标签: java fortify


    【解决方案1】:

    您可以参考问题Prevent mass assignment in Spring MVC with Roo

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

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

    SimpleController.java

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

    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;}
    
    }
    

    【讨论】:

    • 我正在寻找解决方案以解决相同的强化批量分配问题,白名单和黑名单对我的应用程序来说是一项繁琐的任务。除了 spring @InitBinder 之外,还有其他方法可以解决这个问题吗?
    • 在我的项目中,我只是用一种肮脏的方式来解决这个问题。 IE。 @JsonIgnore
    • 我尝试了 JsonView,它比 JsonIgnore 更适合我的项目,因为对象用于多个端点。然而 Fortify 似乎没有识别它
    • 还有一个发现是,Fortify 实际上只是做扫描来弹出警告。有些问题可能没有解决,你只需要理性地接受它。
    • 在我的项目中,我使用了类似@JsonIgnoreProperties(ignoreUnknown=true)
    猜你喜欢
    • 2023-01-19
    • 2018-04-02
    • 2013-07-03
    • 2019-03-09
    • 2010-10-31
    • 1970-01-01
    • 1970-01-01
    • 2013-08-02
    • 2019-08-30
    相关资源
    最近更新 更多