14
14
import javax .servlet .ServletException ;
15
15
import javax .servlet .http .Part ;
16
16
import java .io .IOException ;
17
+ import javax .servlet .ServletException ;
17
18
import java .nio .file .Files ;
18
19
import java .nio .file .StandardCopyOption ;
19
20
20
21
public class UnrestrictedFileUpload {
21
22
22
23
// {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 {
24
25
Part filePart = request .getPart ("fileToUpload" );
25
26
InputStream fileInputStream = filePart .getInputStream ();
26
27
// Noncompliant: the uploaded file can have any extension.
@@ -31,7 +32,7 @@ public void unrestrictedFileUploadNoncompliant(HttpServletRequest request, HttpS
31
32
// {/fact}
32
33
33
34
// {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 {
35
36
Part filePart = request .getPart ("fileToUpload" );
36
37
// Compliant: the uploaded file must have one of the allowed extensions.
37
38
if (filePart .getSubmittedFileName ().endsWith (".jpg" ) || filePart .getSubmittedFileName ().endsWith (".png" )) {
0 commit comments