I am able to generate PDF using JasperReports with the help of below code snippet in desired output format.
Map<String, Object> parameters = new HashMap<>();
parameters.put("code", HtmlUtils.htmlEscape(request.getParameter("code")));
JasperPrint jasperPrint = JasperFillManager.fillReport(path, parameters, dataSource);
barcodePdfBytes = JasperExportManager.exportReportToPdf(jasperPrint);
However when I scan my code using checkmarx it shows Reflected XSS Vulnerability for below code snippet and to fix this i have escaped all input parameters using
HtmlUtils.htmlEscape
but still facing the same issue.
ServletOutputStream outputStream = response.getOutputStream();
outputStream.write(barcodePdfBytes, 0, barcodePdfBytes.length);
I further analysed from my end and tried to sanitised entire byte[]
but it somehow corrupt PDF format and user is not getting pdf inresponse.
Looking for some help here.Would appreciate any pointer. Thanks In Advance.