我保留用户输入请求中的值。查克马克思抱怨有违反信任边界.
从元素请求获取用户输入。该元素的值在没有经过适当清理或验证的情况下流经代码,并最终存储在服务器端 Session 对象中
我还发现这个帖子 https://stackoverflow.com/questions/14977207/how-to-fix-trust-boundary-violation-flaw-in-java-web-application在线的。
接受的答案是验证它。
好的,验证并清理
private String getValidSearchPath(String searchPath) {
if (!searchPath.matches("^[0-9a-zA-Z]+$")) { //using regex to do validation
throw new RuntimeException("Unacceptable jsonPath " + searchPath);
}
if (StringUtils.isBlank(searchPath)) {
return "";
}
return searchPath.substring(0,0); // I intentionally put 0,0 here, which returns ""
}
...
//pseudo code
String searchPath = getValidSearchPath(request.get(...));
persistSearchPath(searchPath);
然后我跑查克马克思 again.
你猜怎么了?我仍然得到违反信任边界。有人可以告诉我如何修复它吗?我已经返回空字符串并且查克马克思仍然抱怨我不正确地使用用户输入的值。
Checkmarx 在代码中搜索一组验证和函数,其中之一是ESAPI库 https://owasp.org/www-project-enterprise-security-api/。使用 ESAPI.getValidInput 方法进行验证:
Validator.SafeString=^[0-9a-zA-Z]+$;
ESAPI.validator().getValidInput("Search Path", searchPath , "SafeString", maxLength, allowNull);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)