Skip to content

Commit 02a16e7

Browse files
geoandvietj
authored andcommitted
Add option for setting max query params
Relates to: quarkusio/quarkus#47431
1 parent 854dd26 commit 02a16e7

File tree

15 files changed

+123
-7
lines changed

15 files changed

+123
-7
lines changed

vertx-core/src/main/generated/io/vertx/core/http/HttpServerOptionsConverter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, HttpSer
8787
obj.setMaxFormBufferedBytes(((Number)member.getValue()).intValue());
8888
}
8989
break;
90+
case "maxQueryParams":
91+
if (member.getValue() instanceof Number) {
92+
obj.setMaxQueryParams(((Number)member.getValue()).intValue());
93+
}
94+
break;
9095
case "initialSettings":
9196
if (member.getValue() instanceof JsonObject) {
9297
obj.setInitialSettings(new io.vertx.core.http.Http2Settings((io.vertx.core.json.JsonObject)member.getValue()));
@@ -214,6 +219,7 @@ static void toJson(HttpServerOptions obj, java.util.Map<String, Object> json) {
214219
json.put("maxFormAttributeSize", obj.getMaxFormAttributeSize());
215220
json.put("maxFormFields", obj.getMaxFormFields());
216221
json.put("maxFormBufferedBytes", obj.getMaxFormBufferedBytes());
222+
json.put("maxQueryParams", obj.getMaxQueryParams());
217223
if (obj.getInitialSettings() != null) {
218224
json.put("initialSettings", obj.getInitialSettings().toJson());
219225
}

vertx-core/src/main/java/io/vertx/core/http/HttpServerConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ private static TcpServerConfig defaultTcpServerConfig() {
6262
private int maxFormAttributeSize;
6363
private int maxFormFields;
6464
private int maxFormBufferedBytes;
65+
private int maxQueryParams;
6566
private boolean handle100ContinueAutomatically;
6667
private ServerSSLOptions sslOptions;
6768
private boolean strictThreadMode;
@@ -91,6 +92,7 @@ public HttpServerConfig(HttpServerOptions options) {
9192
this.maxFormAttributeSize = options.getMaxFormAttributeSize();
9293
this.maxFormFields = options.getMaxFormFields();
9394
this.maxFormBufferedBytes = options.getMaxFormBufferedBytes();
95+
this.maxQueryParams = options.getMaxQueryParams();
9496
this.handle100ContinueAutomatically = options.isHandle100ContinueAutomatically();
9597
this.sslOptions = options.getSslOptions() != null ? new ServerSSLOptions(options.getSslOptions()) : null;
9698
this.strictThreadMode = options.getStrictThreadMode();
@@ -369,6 +371,13 @@ public int getMaxFormFields() {
369371
return maxFormFields;
370372
}
371373

374+
/**
375+
* @return Returns the maximum number of query params
376+
*/
377+
public int getMaxQueryParams() {
378+
return maxQueryParams;
379+
}
380+
372381
/**
373382
* Set the maximum number of fields of a form. Set to {@code -1} to allow unlimited number of attributes
374383
*

vertx-core/src/main/java/io/vertx/core/http/HttpServerOptions.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ public class HttpServerOptions extends NetServerOptions {
101101
*/
102102
public static final int DEFAULT_MAX_FORM_BUFFERED_SIZE = 1024;
103103

104+
/**
105+
* Default max number of query params = 1024
106+
*/
107+
public static final int DEFAULT_MAX_QUERY_PARAMS = 1024;
108+
104109
/**
105110
* Default value of whether 100-Continue should be handled automatically = {@code false}
106111
*/
@@ -209,6 +214,7 @@ public class HttpServerOptions extends NetServerOptions {
209214
private int maxFormAttributeSize;
210215
private int maxFormFields;
211216
private int maxFormBufferedBytes;
217+
private int maxQueryParams;
212218
private Http1ServerConfig http1Config;
213219
private Http2ServerConfig http2Config;
214220
private WebSocketServerConfig webSocketConfig;
@@ -239,6 +245,7 @@ public HttpServerOptions(HttpServerOptions other) {
239245
this.maxFormAttributeSize = other.getMaxFormAttributeSize();
240246
this.maxFormFields = other.getMaxFormFields();
241247
this.maxFormBufferedBytes = other.getMaxFormBufferedBytes();
248+
this.maxQueryParams = other.getMaxQueryParams();
242249
this.compressionLevel = other.getCompressionLevel();
243250
this.compression = other.compression != null ? new HttpCompressionConfig(other.compression) : new HttpCompressionConfig();
244251
this.handle100ContinueAutomatically = other.handle100ContinueAutomatically;
@@ -278,6 +285,7 @@ private void init() {
278285
maxFormAttributeSize = DEFAULT_MAX_FORM_ATTRIBUTE_SIZE;
279286
maxFormFields = DEFAULT_MAX_FORM_FIELDS;
280287
maxFormBufferedBytes = DEFAULT_MAX_FORM_BUFFERED_SIZE;
288+
maxQueryParams = DEFAULT_MAX_QUERY_PARAMS;
281289
strictThreadMode = DEFAULT_STRICT_THREAD_MODE_STRICT;
282290
compression = new HttpCompressionConfig();
283291
handle100ContinueAutomatically = DEFAULT_HANDLE_100_CONTINE_AUTOMATICALLY;
@@ -845,6 +853,24 @@ public HttpServerOptions setMaxFormBufferedBytes(int maxFormBufferedBytes) {
845853
return this;
846854
}
847855

856+
/**
857+
* @return Returns the maximum number of query params
858+
*/
859+
public int getMaxQueryParams() {
860+
return maxQueryParams;
861+
}
862+
863+
/**
864+
* Set the maximum number of query params
865+
*
866+
* @param maxQueryParams the new maximum
867+
* @return a reference to this, so the API can be used fluently
868+
*/
869+
public HttpServerOptions setMaxQueryParams(int maxQueryParams) {
870+
this.maxQueryParams = maxQueryParams;
871+
return this;
872+
}
873+
848874
/**
849875
* @return the initial HTTP/2 connection settings
850876
*/

vertx-core/src/main/java/io/vertx/core/http/impl/HttpServerRequestImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class HttpServerRequestImpl extends HttpServerRequestInternal {
5252
private final int maxFormAttributeSize;
5353
private final int maxFormFields;
5454
private final int maxFormBufferedBytes;
55+
private final int maxQueryParams;
5556
private final Handler<HttpServerRequest> handler;
5657

5758
// Accessed on context thread
@@ -79,6 +80,7 @@ public HttpServerRequestImpl(Handler<HttpServerRequest> handler,
7980
int maxFormAttributeSize,
8081
int maxFormFields,
8182
int maxFormBufferedBytes,
83+
int maxQueryParams,
8284
String serverOrigin) {
8385
this.handler = handler;
8486
this.context = context;
@@ -89,6 +91,7 @@ public HttpServerRequestImpl(Handler<HttpServerRequest> handler,
8991
this.handle100ContinueAutomatically = handle100ContinueAutomatically;
9092
this.maxFormAttributeSize = maxFormAttributeSize;
9193
this.maxFormFields = maxFormFields;
94+
this.maxQueryParams = maxQueryParams;
9295
this.maxFormBufferedBytes = maxFormBufferedBytes;
9396
}
9497

@@ -397,7 +400,7 @@ public String getParamsCharset() {
397400
public MultiMap params(boolean semicolonIsNormalChar) {
398401
synchronized (connection) {
399402
if (params == null || semicolonIsNormalChar != semicolonIsNormalCharInParams) {
400-
params = HttpUtils.params(uri(), paramsCharset, semicolonIsNormalChar);
403+
params = HttpUtils.params(uri(), paramsCharset, maxQueryParams, semicolonIsNormalChar);
401404
semicolonIsNormalCharInParams = semicolonIsNormalChar;
402405
}
403406
return params;

vertx-core/src/main/java/io/vertx/core/http/impl/HttpUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,11 @@ public static String absoluteURI(String serverOrigin, HttpServerRequest req) {
344344
}
345345

346346
public static MultiMap params(String uri, Charset charset, boolean semicolonIsNormalChar) {
347-
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri, charset, true, 1024, semicolonIsNormalChar);
347+
return params(uri, charset, 1024, semicolonIsNormalChar);
348+
}
349+
350+
public static MultiMap params(String uri, Charset charset, int maxParams, boolean semicolonIsNormalChar) {
351+
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri, charset, true, maxParams, semicolonIsNormalChar);
348352
Map<String, List<String>> prms = queryStringDecoder.parameters();
349353
MultiMap params = MultiMap.caseInsensitiveMultiMap();
350354
if (!prms.isEmpty()) {

vertx-core/src/main/java/io/vertx/core/http/impl/http1/Http1ServerConnection.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public class Http1ServerConnection extends Http1Connection implements HttpServer
7878
private final boolean eagerCreateRequestQueue;
7979
private final int maxFormAttributeSize;
8080
private final int maxFormFields;
81+
private final int maxQueryParams;
8182
private final int maxFormBufferedBytes;
8283
private final Http1ServerConfig serverConfig;
8384
private final boolean registerWebSocketWriteHandlers;
@@ -104,6 +105,7 @@ public Http1ServerConnection(ThreadingModel threadingModel,
104105
SslContextManager sslContextManager,
105106
int maxFormAttributeSize,
106107
int maxFormFields,
108+
int maxQueryParams,
107109
int maxFormBufferedBytes,
108110
Http1ServerConfig serverConfig,
109111
boolean registerWebSocketWriteHandlers,
@@ -119,6 +121,7 @@ public Http1ServerConnection(ThreadingModel threadingModel,
119121
this.streamContextSupplier = streamContextSupplier;
120122
this.maxFormAttributeSize = maxFormAttributeSize;
121123
this.maxFormFields = maxFormFields;
124+
this.maxQueryParams = maxQueryParams;
122125
this.maxFormBufferedBytes = maxFormBufferedBytes;
123126
this.serverConfig = serverConfig;
124127
this.registerWebSocketWriteHandlers = registerWebSocketWriteHandlers;
@@ -142,6 +145,10 @@ int maxFormFields() {
142145
return maxFormFields;
143146
}
144147

148+
int maxQueryParams() {
149+
return maxQueryParams;
150+
}
151+
145152
int maxFormBufferedBytes() {
146153
return maxFormBufferedBytes;
147154
}

vertx-core/src/main/java/io/vertx/core/http/impl/http1/Http1ServerRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public String getParamsCharset() {
337337
@Override
338338
public MultiMap params(boolean semicolonIsNormalChar) {
339339
if (params == null || semicolonIsNormalChar != semicolonIsNormalCharInParams) {
340-
params = HttpUtils.params(uri(), paramsCharset, semicolonIsNormalChar);
340+
params = HttpUtils.params(uri(), paramsCharset, this.conn.maxQueryParams(), semicolonIsNormalChar);
341341
semicolonIsNormalCharInParams = semicolonIsNormalChar;
342342
}
343343
return params;

vertx-core/src/main/java/io/vertx/core/http/impl/quic/QuicHttpServer.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ private static class ConnectionHandler implements Handler<QuicConnection> {
132132
private final boolean handle100ContinueAutomatically;
133133
private final int maxFormAttributeSize;
134134
private final int maxFormFields;
135+
private final int maxQueryParams;
135136
private final int maxFormBufferedSize;
136137
private final Http3Settings localSettings;
137138

@@ -142,6 +143,7 @@ public ConnectionHandler(QuicServer transport,
142143
boolean handle100ContinueAutomatically,
143144
int maxFormAttributeSize,
144145
int maxFormFields,
146+
int maxQueryParams,
145147
int maxFormBufferedSize,
146148
Http3Settings localSettings) {
147149
this.transport = transport;
@@ -151,6 +153,7 @@ public ConnectionHandler(QuicServer transport,
151153
this.handle100ContinueAutomatically = handle100ContinueAutomatically;
152154
this.maxFormAttributeSize = maxFormAttributeSize;
153155
this.maxFormFields = maxFormFields;
156+
this.maxQueryParams = maxQueryParams;
154157
this.maxFormBufferedSize = maxFormBufferedSize;
155158
this.localSettings = localSettings;
156159
}
@@ -170,7 +173,7 @@ public void handle(QuicConnection connection) {
170173
http3Connection.streamHandler(stream -> {
171174
HttpServerRequestImpl request = new HttpServerRequestImpl(requestHandler, stream, stream.context(),
172175
handle100ContinueAutomatically, maxFormAttributeSize,
173-
maxFormFields, maxFormBufferedSize, serverOrigin);
176+
maxFormFields, maxFormBufferedSize, maxQueryParams, serverOrigin);
174177
request.init();
175178
});
176179

@@ -221,7 +224,8 @@ public Future<HttpServer> listen(ContextInternal current, SocketAddress address)
221224
}
222225

223226
quicServer.handler(new ConnectionHandler(quicServer, httpMetrics, requestHandler, connectionHandler,
224-
config.isHandle100ContinueAutomatically(), config.getMaxFormAttributeSize(), config.getMaxFormFields(),
227+
config.isHandle100ContinueAutomatically(), config.getMaxFormAttributeSize(),
228+
config.getMaxFormFields(), config.getMaxQueryParams(),
225229
config.getMaxFormBufferedBytes(), http3Config.getInitialSettings() != null ? http3Config.getInitialSettings().copy() : new Http3Settings()));
226230
return quicServer
227231
.bind(current, address)

vertx-core/src/main/java/io/vertx/core/http/impl/tcp/HttpServerConnectionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void handle(HttpServerConnection conn) {
101101
HttpServerConfig config = server.config;
102102
HttpServerRequestImpl request = new HttpServerRequestImpl(requestHandler, stream, stream.context(),
103103
config.isHandle100ContinueAutomatically(), config.getMaxFormAttributeSize(), config.getMaxFormFields(),
104-
config.getMaxFormBufferedBytes(), serverOrigin);
104+
config.getMaxFormBufferedBytes(), config.getMaxQueryParams(), serverOrigin);
105105
request.init();
106106
});
107107
}

vertx-core/src/main/java/io/vertx/core/http/impl/tcp/HttpServerConnectionInitializer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public class HttpServerConnectionInitializer {
6767
private final boolean handle100ContinueAutomatically;
6868
private final int maxFormAttributeSize;
6969
private final int maxFormFields;
70+
private final int maxQueryParams;
7071
private final int maxFormBufferedBytes;
7172
private final Http1ServerConfig http1Config;
7273
private final Http2ServerConfig http2Config;
@@ -92,6 +93,7 @@ public HttpServerConnectionInitializer(ContextInternal context,
9293
boolean handle100ContinueAutomatically,
9394
int maxFormAttributeSize,
9495
int maxFormFields,
96+
int maxQueryParams,
9597
int maxFormBufferedBytes,
9698
Http1ServerConfig http1Config,
9799
Http2ServerConfig http2Config,
@@ -154,6 +156,7 @@ public HttpServerConnectionInitializer(ContextInternal context,
154156
this.handle100ContinueAutomatically = handle100ContinueAutomatically;
155157
this.maxFormAttributeSize = maxFormAttributeSize;
156158
this.maxFormFields = maxFormFields;
159+
this.maxQueryParams = maxQueryParams;
157160
this.maxFormBufferedBytes = maxFormBufferedBytes;
158161
this.http1Config = http1Config;
159162
this.http2Config = http2Config;
@@ -297,6 +300,7 @@ public void configureHttp1Handler(ChannelPipeline pipeline, SslContextManager ss
297300
sslContextManager,
298301
maxFormAttributeSize,
299302
maxFormFields,
303+
maxQueryParams,
300304
maxFormBufferedBytes,
301305
http1Config,
302306
registerWebSocketWriteHandlers,

0 commit comments

Comments
 (0)