I am struggling with one of the CheckMarx vulnerabilities. I need some guidance to support this. Below is my code :
try(Bufferedreader in = new BufferedReader(new InputStreamReader(con.getInputStream()))){
String content = null;
while((content = in.readLine()) != null) {
// Logic to Parse JSON data and use it.
}
}
Here con is (HttpurlConnection) new URL("some url").openConnection().
So, checkmarx is highlighting issue at in.readLine().
Workarounds I tried:
1: StringEscapeUtils.unescapeJson(in.readLine()), it's not helping.
2: Used in.lines().collect(Collectors.joining()) in place of in.readline() by reading somewhere in google. It helped to fix this but introduced a new one at con.getInputStream() (the same vulnerability).
Please help to fix this issue. Thanks in advance.