Fix user controlled input sonar finding - add content type (#2013)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-11-12 09:57:18 +02:00
committed by GitHub
parent 32acb44e31
commit 1e6c9d5efe

View File

@@ -782,18 +782,16 @@ public class DdiRootController implements DdiRootControllerRestApi {
* @return the response
* @throws IOException cannot write output stream
*/
private static ResponseEntity<Void> writeMD5FileResponse(
private static void writeMD5FileResponse(
final HttpServletResponse response, final String md5Hash, final String filename) throws IOException {
if (md5Hash == null) {
return ResponseEntity.notFound().build();
throw new IllegalArgumentException("MD5 hash must not be null");
}
final byte[] content = (md5Hash + " " + filename).getBytes(StandardCharsets.US_ASCII);
response.setContentType("text/plain");
response.setContentLength(content.length);
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + filename + ARTIFACT_MD5_DWNL_SUFFIX);
response.getOutputStream().write(content);
return ResponseEntity.ok().build();
}
}