Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.zip file downloaded as f.txt file - springboot

Below code is always downloading a f.txt file rather downloading without the actual file name and extension(here .zip extension).

@RequestMapping(value = "/files/{fileId}", method = RequestMethod.GET, produces = "application/zip")
    public ResponseEntity<Resource> downloadFile(@PathVariable("fileId") String fileName) {
        log.info("Downloading file..!!!!");
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.valueOf("application/zip"));
        log.info("Content info : "+headers.getContentType().toString());
        File file = FileUtils.getFile("backup/" + fileName + ".zip");
        log.info("File name is : "+file.getName());
        FileSystemResource fileSystemResource = new FileSystemResource(file);

        return new ResponseEntity<>(fileSystemResource, headers, HttpStatus.OK);
    }

It would be great if someone can let me know where the mistake is/ some amendments to be done?

like image 873
harshavmb Avatar asked Dec 15 '22 01:12

harshavmb


1 Answers

f.txt is coming from the Content-Disposition response header. This is a consequence of fixing cve-2015-5211 (RFD Attack)

like image 80
Stephane Nicoll Avatar answered Jan 23 '23 05:01

Stephane Nicoll