I use Tomcat8/Java
I currently allow sensitive user-generated Excel files (created in Java/POI) to be downloaded from the server by creating a file name with a GUID and then saving it in a publicly available directory, and providing the link for this file.
Stage 1
The User selects various parameters, which the JSP sends to a Java file
String fileName = "excelFiles/"
+ myReports
.createExcel(listCompanyDetails);
public static String createExcel(List listCompanyDetails) {
String fileName = "MyFile"+UUID.randomUUID() + ".xls";
String fileFullPath="\..."+fileName;
FileInputStream inputStream = new FileInputStream(new File(APPCodeTable.templateExcelFile));
Workbook wb=new HSSFWorkbook(inputStream);
FileOutputStream out = new FileOutputStream(fileFullPath);
wb.write(out);
out.close();
}
Stage 2
The JSP then displays the file in an iFrame
<iframe id="target_upload" name="target_upload" width="100%"
src="<%=fileName%>" height="100%"></iframe>
The results of a Penetration Test done on our system said that we should instead produce the file in a stream from a jsp file, and this would be more secure, as it would avoid the use of GUID's, and would avoid having a direct link to the file which would bypass the login authorization.
It seems however that it is better coding practice to use a servlet. For instance Implementing a simple file download servlet.
I was considering saving the document on the server, identified by a GUID, and then passing this GUID to the servlet. However this seems to defeat my original intentions of improving security.
If I implement a simple download servlet (as in the attached link), how can I get my created file inside that servlet?