gpt4 book ai didi

java - 如何在 java 中修复 Mass Assignment : Insecure Binder Configuration (API Abuse, Structural)

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:12:11 53 4
gpt4 key购买 nike

我有一个 Controller 类,其中包含以下两种查找医生的方法(上下文已更改)。获取Mass Assignment: Insecure Binder Configuration (API Abuse, Structural) 两种方法都出现错误。

@Controller
@RequestMapping(value = "/findDocSearch")
public class Controller {

@Autowired
private IFindDocService findDocService;

@RequestMapping(value = "/byName", method = RequestMethod.GET)
@ResponseBody
public List<FindDocDTO> findDocByName(FindDocBean bean) {
return findDocService.retrieveDocByName(bean.getName());
}

@RequestMapping(value = "/byLoc", method = RequestMethod.GET)
@ResponseBody
public List<FindDocDTO> findDocByLocation(FindDocBean bean) {
return findDocService.retrieveDocByZipCode(bean.getZipcode(),
bean.getDistance());
}
}

我的 Bean 是:

public class FindDocBean implements Serializable {
private static final long serialVersionUID = -1212xxxL;

private String name;
private String zipcode;
private int distance;

@Override
public String toString() {
return String.format("FindDocBean[name: %s, zipcode:%s, distance:%s]",
name, zipcode, distance);
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getZipcode() {
return zipcode;
}

public void setZipcode(String zipcode) {
this.zipcode = zipcode;
}

public int getDistance() {
return distance;
}

public void setDistance(int distance) {
this.distance = distance;
}

根据目前发现的所有建议,他们建议仅通过以下方式限制具有必需参数的 bean:

final String[] DISALLOWED_FIELDS = new String[]{"bean.name", "bean.zipcode", };

@InitBinder
public void initBinder(WebDataBinder binder) {
binder.setDisallowedFields(DISALLOWED_FIELDS);

但我的问题是 bean 的所有 3 个参数都将用在 Controller 上提供的任一方法中。

有人可以为此提出一些解决方案吗?提前致谢。

最佳答案

InitBinder 可用于方法。你可以试试这个。

@InitBinder("findDocByName")
public void initBinderByName(WebDataBinder binder) {
binder.setDisallowedFields(new String[]{"distance","zipcode"});
}


@InitBinder("findDocByLocation")
public void initBinderByZipCode(WebDataBinder binder) {
binder.setDisallowedFields(new String[]{"distance","name"});
}

关于java - 如何在 java 中修复 Mass Assignment : Insecure Binder Configuration (API Abuse, Structural),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47945383/

53 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com