I need to read the properties file kept in user_home folder.
PropsFile = System.getProperty("user.home") + System.getProperty("file.separator")+ "x.properties";
Fortify is giving path manipulation error in this line. The number of correct values is large so blacklisting is the only way possible. So to avoid it i changed the code as below.
String propsFile = null;
StringBuffer sb = new StringBuffer();
String xProperties = "x.properties";
String userHome = System.getProperty("user.home"); // *
if(userHome.contains("..\\"))
userHome = userHome.replace("..\\", "");
if(userHome.contains("../"))
userHome = userHome.replace("../", "");
if(userHome.contains("./"))
userHome = userHome.replace("./", "");
String fileSeperator = System.getProperty("file.separator"); // *
if(fileSeperator.equals("/") || fileSeperator.equals("\\")){
sb = sb.append(userHome).append(fileSeperator).append(xProperties);
propsFile = sb.toString();
}
but still fortify is giving me the same errors in (*) marked lines ( although the validation is done ). How can i remove the error ?