Skip to content

Commit

Permalink
Add the ability to configure the maximum form attribute size
Browse files Browse the repository at this point in the history
Vert.x defaults to 2K and prior to this PR we didn't have
a way to configure it.

Fixes: #16422
  • Loading branch information
geoand committed Apr 12, 2021
1 parent 851ef0a commit 942efd3
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package io.quarkus.resteasy.reactive.server.test.multipart;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.function.Supplier;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.jboss.resteasy.reactive.MultipartForm;
import org.jboss.resteasy.reactive.PartType;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.restassured.http.ContentType;
import io.vertx.core.http.HttpServerOptions;

public class LargeMultipartFormInputTest {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.setArchiveProducer(new Supplier<JavaArchive>() {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class)
.addClasses(Resource.class, Data.class)
.addAsResource(new StringAsset(
"quarkus.http.limits.max-form-attribute-size=4K"),
"application.properties");
}
});

private static final File FILE = new File("./src/test/resources/larger-than-default-form-attribute.txt");

@Test
public void test() throws IOException {
String fileContents = new String(Files.readAllBytes(FILE.toPath()), StandardCharsets.UTF_8);
Assertions.assertTrue(fileContents.length() > HttpServerOptions.DEFAULT_MAX_FORM_ATTRIBUTE_SIZE);
given()
.multiPart("text", fileContents)
.accept("text/plain")
.when()
.post("/test")
.then()
.statusCode(200)
.contentType(ContentType.TEXT)
.body(equalTo(fileContents));
}

@Path("/test")
public static class Resource {

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public String hello(@MultipartForm Data data) {
return data.getText();
}
}

public static class Data {
@FormParam("text")
@PartType("text/plain")
private String text;

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
File-Date: 2018-04-23
%%
Type: language
Subtag: aa
Description: Afar
Added: 2005-10-16
%%
Type: language
Subtag: ab
Description: Abkhazian
Added: 2005-10-16
Suppress-Script: Cyrl
%%
Type: language
Subtag: ae
Description: Avestan
Added: 2005-10-16
%%
Type: language
Subtag: af
Description: Afrikaans
Added: 2005-10-16
Suppress-Script: Latn
%%
Type: language
Subtag: ak
Description: Akan
Added: 2005-10-16
Scope: macrolanguage
%%
Type: language
Subtag: am
Description: Amharic
Added: 2005-10-16
Suppress-Script: Ethi
%%
Type: language
Subtag: an
Description: Aragonese
Added: 2005-10-16
%%
Type: language
Subtag: ar
Description: Arabic
Added: 2005-10-16
Suppress-Script: Arab
Scope: macrolanguage
%%
Type: language
Subtag: as
Description: Assamese
Added: 2005-10-16
Suppress-Script: Beng
%%
Type: language
Subtag: av
Description: Avaric
Added: 2005-10-16
%%
Type: language
Subtag: ay
Description: Aymara
Added: 2005-10-16
Suppress-Script: Latn
Scope: macrolanguage
%%
Type: language
Subtag: az
Description: Azerbaijani
Added: 2005-10-16
Scope: macrolanguage
%%
Type: language
Subtag: ba
Description: Bashkir
Added: 2005-10-16
%%
Type: language
Subtag: be
Description: Belarusian
Added: 2005-10-16
Suppress-Script: Cyrl
%%
Type: language
Subtag: bg
Description: Bulgarian
Added: 2005-10-16
Suppress-Script: Cyrl
%%
Type: language
Subtag: bh
Description: Bihari languages
Added: 2005-10-16
Scope: collection
%%
Type: language
Subtag: bi
Description: Bislama
Added: 2005-10-16
%%
Type: language
Subtag: bm
Description: Bambara
Added: 2005-10-16
%%
Type: language
Subtag: bn
Description: Bengali
Description: Bangla
Added: 2005-10-16
Suppress-Script: Beng
%%
Type: language
Subtag: bo
Description: Tibetan
Added: 2005-10-16
%%
Type: language
Subtag: br
Description: Breton
Added: 2005-10-16
%%
Type: language
Subtag: bs
Description: Bosnian
Added: 2005-10-16
Suppress-Script: Latn
Macrolanguage: sh
%%
Type: language
Subtag: ca
Description: Catalan
Description: Valencian
Added: 2005-10-16
Suppress-Script: Latn
%%
Type: language
Subtag: ce
Description:
%%
Type: language
Subtag: ce
Description:
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ public class ServerLimitsConfig {
@ConfigItem(defaultValue = "4096")
public int maxInitialLineLength;

/**
* The maximum length of a form attribute.
*/
@ConfigItem(defaultValue = "2048")
public MemorySize maxFormAttributeSize;

}
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ private static HttpServerOptions createSslOptions(HttpBuildTimeConfig buildTimeC
}
serverOptions.setMaxHeaderSize(httpConfiguration.limits.maxHeaderSize.asBigInteger().intValueExact());
serverOptions.setMaxChunkSize(httpConfiguration.limits.maxChunkSize.asBigInteger().intValueExact());
serverOptions.setMaxFormAttributeSize(httpConfiguration.limits.maxFormAttributeSize.asBigInteger().intValueExact());
setIdleTimeout(httpConfiguration, serverOptions);

if (certFile.isPresent() && keyFile.isPresent()) {
Expand Down Expand Up @@ -725,6 +726,7 @@ private static HttpServerOptions createHttpServerOptions(HttpConfiguration httpC
setIdleTimeout(httpConfiguration, options);
options.setMaxHeaderSize(httpConfiguration.limits.maxHeaderSize.asBigInteger().intValueExact());
options.setMaxChunkSize(httpConfiguration.limits.maxChunkSize.asBigInteger().intValueExact());
options.setMaxFormAttributeSize(httpConfiguration.limits.maxFormAttributeSize.asBigInteger().intValueExact());
options.setWebSocketSubProtocols(websocketSubProtocols);
options.setReusePort(httpConfiguration.soReusePort);
options.setTcpQuickAck(httpConfiguration.tcpQuickAck);
Expand All @@ -745,6 +747,7 @@ private static HttpServerOptions createDomainSocketOptions(HttpConfiguration htt
setIdleTimeout(httpConfiguration, options);
options.setMaxHeaderSize(httpConfiguration.limits.maxHeaderSize.asBigInteger().intValueExact());
options.setMaxChunkSize(httpConfiguration.limits.maxChunkSize.asBigInteger().intValueExact());
options.setMaxFormAttributeSize(httpConfiguration.limits.maxFormAttributeSize.asBigInteger().intValueExact());
options.setWebSocketSubProtocols(websocketSubProtocols);
return options;
}
Expand Down

0 comments on commit 942efd3

Please sign in to comment.