From 1fe57aa9ae2451c6c765f4e172f1679a435e007c Mon Sep 17 00:00:00 2001 From: Riya Date: Thu, 14 Dec 2023 20:07:33 +0530 Subject: [PATCH] Add compliant and noncompliant examples of java/unrestricted-file-upload@v1.0 --- .../unrestricted_file_upload/UnrestrictedFileUpload.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/java/detectors/unrestricted_file_upload/UnrestrictedFileUpload.java b/src/java/detectors/unrestricted_file_upload/UnrestrictedFileUpload.java index 7b54634..d680240 100644 --- a/src/java/detectors/unrestricted_file_upload/UnrestrictedFileUpload.java +++ b/src/java/detectors/unrestricted_file_upload/UnrestrictedFileUpload.java @@ -12,11 +12,14 @@ import java.util.HashMap; import org.springframework.util.StringUtils; import javax.servlet.ServletException; +import javax.servlet.http.Part; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; public class UnrestrictedFileUpload { // {fact rule=unrestricted-file-upload@v1.0 defects=1} - public void unrestrictedFileUploadNoncompliant(HttpServletRequest request) { + public void unrestrictedFileUploadNoncompliant(HttpServletRequest request, HttpServletResponse response) { Part filePart = request.getPart("fileToUpload"); InputStream fileInputStream = filePart.getInputStream(); // Noncompliant: the uploaded file can have any extension.