Skip to content

Commit 27c006a

Browse files
committed
Add compliant and noncompliant examples of java/unrestricted-file-upload@v1.0
1 parent a618181 commit 27c006a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/java/detectors/unrestricted_file_upload/UnrestrictedFileUpload.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
import javax.servlet.ServletException;
1515
import javax.servlet.http.Part;
1616
import java.io.IOException;
17+
import javax.servlet.ServletException;
1718
import java.nio.file.Files;
1819
import java.nio.file.StandardCopyOption;
1920

2021
public class UnrestrictedFileUpload {
2122

2223
// {fact rule=unrestricted-file-upload@v1.0 defects=1}
23-
public void unrestrictedFileUploadNoncompliant(HttpServletRequest request, HttpServletResponse response) throws IOException {
24+
public void unrestrictedFileUploadNoncompliant(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
2425
Part filePart = request.getPart("fileToUpload");
2526
InputStream fileInputStream = filePart.getInputStream();
2627
// Noncompliant: the uploaded file can have any extension.
@@ -31,7 +32,7 @@ public void unrestrictedFileUploadNoncompliant(HttpServletRequest request, HttpS
3132
// {/fact}
3233

3334
// {fact rule=unrestricted-file-upload@v1.0 defects=0}
34-
public void unrestrictedFileUploadCompliant(HttpServletRequest request, HttpServletResponse response) throws IOException {
35+
public void unrestrictedFileUploadCompliant(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
3536
Part filePart = request.getPart("fileToUpload");
3637
// Compliant: the uploaded file must have one of the allowed extensions.
3738
if (filePart.getSubmittedFileName().endsWith(".jpg") || filePart.getSubmittedFileName().endsWith(".png")) {

0 commit comments

Comments
 (0)