I am reading a JSON file in java 11 as shown below but upon analyzing with sonar Qube I am getting the error on scanning it, please let me know how to overcome from this:
File file = ResourceUtils.getFile("classpath:8Aug.json");
byte[] bFile = readAllBytes(Paths.get(file.getAbsolutePath()));
The error that I am getting is on scanning with sonar Qube is shown below:
java/nio/file/Paths.get(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path; reads a file whose location might be specified by user input, A file is opened to read its content. The filename comes from an input parameter. If an unfiltered parameter is passed to this file API, files from an arbitrary filesystem location could be read.
This rule identifies potential path traversal vulnerabilities. In many cases, the constructed file path cannot be controlled by the user. If that is the case, the reported instance is false positive.