admin管理员组文章数量:1122832
My application Spring Boot 3 Mvc has the following controller method:
@RequestMapping(value = "/addToCart", method = RequestMethod.POST)
public String addToCart(WebRequest webRequest, HttpServletRequest request) throws Exception {
String[] quantity= request.getParameterValues("qty");
String[] itemNumbers = request.getParameterValues("itemNumber");
return addToCartHelper(webRequest, request, qtys, itemNumbers);
}
VeraCode points to CWE-73 vulnerability on line "return addToCartHelper(webRequest, request, qtys, itemNumbers);"
CWE-73: External Control of File Name or Path: Link to description
Inside "addToCartHelper" method I access the MongoDB repository and generate the view URL for the redirect.
I don't interact with the file system.
Can you tell me how to fix the vulnerability?
My application Spring Boot 3 Mvc has the following controller method:
@RequestMapping(value = "/addToCart", method = RequestMethod.POST)
public String addToCart(WebRequest webRequest, HttpServletRequest request) throws Exception {
String[] quantity= request.getParameterValues("qty");
String[] itemNumbers = request.getParameterValues("itemNumber");
return addToCartHelper(webRequest, request, qtys, itemNumbers);
}
VeraCode points to CWE-73 vulnerability on line "return addToCartHelper(webRequest, request, qtys, itemNumbers);"
CWE-73: External Control of File Name or Path: Link to description
Inside "addToCartHelper" method I access the MongoDB repository and generate the view URL for the redirect.
I don't interact with the file system.
Can you tell me how to fix the vulnerability?
Share Improve this question edited Nov 21, 2024 at 14:19 Heorhi Utseuski asked Nov 21, 2024 at 13:40 Heorhi UtseuskiHeorhi Utseuski 236 bronze badges 2- What is **CWE-73 vulnerability **. You expect us to know that... – M. Deinum Commented Nov 21, 2024 at 14:01
- @M.Deinum Sorry, I edited the question description, added a link to the description. – Heorhi Utseuski Commented Nov 21, 2024 at 14:20
1 Answer
Reset to default 0Your code has several problems from a security perspective, but first and foremost you're not even validating the parameters before you're using them. When receiving input from a user you always
1.) Assert that it's malicious 2.) Treat it as such
It's not clear why you're getting a path vuln flag, maybe see what happens if you send in <url>/addToCart/../../
and see what happens? Maybe at the root context of your application you're not defending against directory traversal which is more what this smells like based on the CWE-73.
But for sure, even if you clear CWE-73, you're not validating that the parameter values are
1.) In a valid range //String.length > 0 && String.length <= Integer.MAX_VALUE
to get you started
2.) Are actually numbers (since that's what you expect) // [0-9]+
Afterwards, before you pass that data to the database, ensure they're using parameterized queries (or whatever the equivalent is in MongoDB).
At any rate, I'd answer the traversal question by using the testing guide I linked, and then determine if it's valid. You can also use a tool like DirBuster against a running instance of your web app to test and see if you're not handling paths correctly.
本文标签: spring bootVeraCode static scan CWE73 External Control of File Name or PathStack Overflow
版权声明:本文标题:spring boot - VeraCode static scan CWE-73: External Control of File Name or Path - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736310376a1934354.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论