I am facing path traversal vulnerability while analyzing code through checkmarx. I am fetching path with below code:
String path = System.getenv(variableName);
and "path" variable value is traversing through many functions and finally used in one function with below code snippet:
File file = new File(path);
Checkmarx is marking it as medium severity vulnerability.
Please help. How to resolve it to make it compatible with checkmarx?
You can generate canonicalized path by calling
File.getCanonicalPath().In your case:
For more information read Java Doc