Skip to content

Commit 51ea4a4

Browse files
author
Dennis Kieselhorst
authored
Merge pull request #551 from mbfreder/commons
Remove commons-fileupload
2 parents 04d8509 + ac04f4c commit 51ea4a4

File tree

7 files changed

+13
-53
lines changed

7 files changed

+13
-53
lines changed

aws-serverless-java-container-core/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
</dependency>
6868

6969
<dependency>
70-
<groupId>org.apache.commons</groupId>
71-
<artifactId>commons-fileupload2</artifactId>
72-
<version>2.0-SNAPSHOT</version>
70+
<groupId>commons-io</groupId>
71+
<artifactId>commons-io</artifactId>
72+
<version>2.12.0</version>
7373
</dependency>
7474

7575
<dependency>

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpServletRequest.java

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222
import com.amazonaws.serverless.proxy.model.MultiValuedTreeMap;
2323
import com.amazonaws.services.lambda.runtime.Context;
2424
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
25-
import org.apache.commons.fileupload2.FileItem;
26-
import org.apache.commons.fileupload2.FileUploadException;
27-
import org.apache.commons.fileupload2.disk.DiskFileItemFactory;
28-
import org.apache.commons.fileupload2.jaksrvlt.JakSrvltFileUpload;
29-
import org.apache.commons.io.FilenameUtils;
3025
import org.apache.commons.io.IOUtils;
3126
import org.apache.commons.io.input.NullInputStream;
3227
import org.slf4j.Logger;
@@ -508,39 +503,7 @@ protected Map<String, List<String>> getFormUrlEncodedParametersMap() {
508503

509504
@SuppressFBWarnings({"FILE_UPLOAD_FILENAME", "WEAK_FILENAMEUTILS"})
510505
protected Map<String, Part> getMultipartFormParametersMap() {
511-
if (multipartFormParameters != null) {
512-
return multipartFormParameters;
513-
}
514-
if (!JakSrvltFileUpload.isMultipartContent(this)) { // isMultipartContent also checks the content type
515-
multipartFormParameters = new HashMap<>();
516-
return multipartFormParameters;
517-
}
518-
Timer.start("SERVLET_REQUEST_GET_MULTIPART_PARAMS");
519-
multipartFormParameters = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
520-
521-
JakSrvltFileUpload upload = new JakSrvltFileUpload(new DiskFileItemFactory());
522-
523-
try {
524-
List<FileItem> items = upload.parseRequest(this);
525-
for (FileItem item : items) {
526-
String fileName = FilenameUtils.getName(item.getName());
527-
AwsProxyRequestPart newPart = new AwsProxyRequestPart(item.get());
528-
newPart.setName(item.getFieldName());
529-
newPart.setSubmittedFileName(fileName);
530-
newPart.setContentType(item.getContentType());
531-
newPart.setSize(item.getSize());
532-
item.getHeaders().getHeaderNames().forEachRemaining(h -> {
533-
newPart.addHeader(h, item.getHeaders().getHeader(h));
534-
});
535-
536-
multipartFormParameters.put(item.getFieldName(), newPart);
537-
}
538-
} catch (FileUploadException e) {
539-
Timer.stop("SERVLET_REQUEST_GET_MULTIPART_PARAMS");
540-
log.error("Could not read multipart upload file", e);
541-
}
542-
Timer.stop("SERVLET_REQUEST_GET_MULTIPART_PARAMS");
543-
return multipartFormParameters;
506+
throw new UnsupportedOperationException();
544507
}
545508

546509
protected String[] getQueryParamValues(MultiValuedTreeMap<String, String> qs, String key, boolean isCaseSensitive) {

aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/servlet/AwsProxyHttpServletRequestFormTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import org.apache.commons.io.IOUtils;
88
import org.apache.hc.core5.http.ContentType;
99
import org.apache.hc.core5.http.HttpEntity;
10-
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;;
10+
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
11+
import org.junit.jupiter.api.Disabled;
1112
import org.junit.jupiter.api.Test;
1213

1314
import jakarta.servlet.ServletException;
@@ -51,6 +52,7 @@ public class AwsProxyHttpServletRequestFormTest {
5152
.build();
5253
private static final String ENCODED_FORM_ENTITY = PART_KEY_1 + "=" + ENCODED_VALUE + "&" + PART_KEY_2 + "=" + PART_VALUE_2;
5354

55+
@Disabled("Disabled until new release of commons-fileupload based on Jakarta APIs")
5456
@Test
5557
void postForm_getParam_getEncodedFullValue() {
5658
try {
@@ -67,6 +69,7 @@ void postForm_getParam_getEncodedFullValue() {
6769
}
6870
}
6971

72+
@Disabled("Disabled until new release of commons-fileupload based on Jakarta APIs")
7073
@Test
7174
void postForm_getParts_parsing() {
7275
try {
@@ -86,6 +89,7 @@ void postForm_getParts_parsing() {
8689
}
8790
}
8891

92+
@Disabled("Disabled until new release of commons-fileupload based on Jakarta APIs")
8993
@Test
9094
void multipart_getParts_binary() {
9195
try {

aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/testutils/AwsProxyRequestBuilder.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,7 @@ public AwsProxyRequestBuilder form(String key, String value) {
155155
}
156156

157157
public AwsProxyRequestBuilder formFilePart(String fieldName, String fileName, byte[] content) throws IOException {
158-
if (multipartBuilder == null) {
159-
multipartBuilder = MultipartEntityBuilder.create();
160-
}
161-
multipartBuilder.addPart(fieldName, new ByteArrayBody(content, fileName));
162-
buildMultipartBody();
163-
return this;
158+
throw new UnsupportedOperationException();
164159
}
165160

166161
public AwsProxyRequestBuilder formTextFieldPart(String fieldName, String fieldValue)

aws-serverless-java-container-jersey/src/test/java/com/amazonaws/serverless/proxy/jersey/JerseyParamEncodingTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ void queryParam_listOfString_expectCorrectLength(String reqType) {
263263
validateSingleValueModel(resp, "3");
264264
}
265265

266+
@Disabled("Disabled until new release of commons-fileupload based on Jakarta APIs")
266267
@MethodSource("data")
267268
@ParameterizedTest
268269
void multipart_getFileSize_expectCorrectLength(String reqType)

aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringAwsProxyTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.fasterxml.jackson.databind.ObjectMapper;
2020
import org.apache.commons.codec.binary.Base64;
2121
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Disabled;
2223
import org.junit.jupiter.params.ParameterizedTest;
2324
import org.junit.jupiter.params.provider.MethodSource;
2425
import org.springframework.web.servlet.DispatcherServlet;
@@ -468,6 +469,7 @@ void contextPath_generateLink_returnsCorrectPath(String reqType) {
468469
SpringLambdaContainerHandler.getContainerConfig().setUseStageAsServletContext(false);
469470
}
470471

472+
@Disabled("Disabled until new release of commons-fileupload based on Jakarta APIs")
471473
@MethodSource("data")
472474
@ParameterizedTest
473475
void multipart_getFileName_returnsCorrectFileName(String reqType)

aws-serverless-java-container-struts/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@
9494

9595
<dependencyManagement>
9696
<dependencies>
97-
<dependency><!-- [CVE-2021-29425] commons-fileupload ships with 2.2 -->
98-
<groupId>commons-io</groupId>
99-
<artifactId>commons-io</artifactId>
100-
<version>2.11.0</version>
101-
</dependency>
10297
<dependency><!-- [CVE-2022-42889] transitive dep via Struts -->
10398
<groupId>org.apache.commons</groupId>
10499
<artifactId>commons-text</artifactId>

0 commit comments

Comments
 (0)