Skip to content

Commit 4f4a030

Browse files
committed
Add option for setting max query params
Relates to: quarkusio/quarkus#47431
1 parent caa3962 commit 4f4a030

File tree

15 files changed

+122
-7
lines changed

15 files changed

+122
-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
@@ -77,6 +77,7 @@ public class Http1ServerConnection extends Http1Connection implements HttpServer
7777
private final boolean eagerCreateRequestQueue;
7878
private final int maxFormAttributeSize;
7979
private final int maxFormFields;
80+
private final int maxQueryParams;
8081
private final int maxFormBufferedBytes;
8182
private final Http1ServerConfig serverConfig;
8283
private final boolean registerWebSocketWriteHandlers;
@@ -102,6 +103,7 @@ public Http1ServerConnection(ThreadingModel threadingModel,
102103
SslContextManager sslContextManager,
103104
int maxFormAttributeSize,
104105
int maxFormFields,
106+
int maxQueryParams,
105107
int maxFormBufferedBytes,
106108
Http1ServerConfig serverConfig,
107109
boolean registerWebSocketWriteHandlers,
@@ -116,6 +118,7 @@ public Http1ServerConnection(ThreadingModel threadingModel,
116118
this.streamContextSupplier = streamContextSupplier;
117119
this.maxFormAttributeSize = maxFormAttributeSize;
118120
this.maxFormFields = maxFormFields;
121+
this.maxQueryParams = maxQueryParams;
119122
this.maxFormBufferedBytes = maxFormBufferedBytes;
120123
this.serverConfig = serverConfig;
121124
this.registerWebSocketWriteHandlers = registerWebSocketWriteHandlers;
@@ -138,6 +141,10 @@ int maxFormFields() {
138141
return maxFormFields;
139142
}
140143

144+
int maxQueryParams() {
145+
return maxQueryParams;
146+
}
147+
141148
int maxFormBufferedBytes() {
142149
return maxFormBufferedBytes;
143150
}

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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ private static class ConnectionHandler implements Handler<QuicConnection> {
136136
private final boolean handle100ContinueAutomatically;
137137
private final int maxFormAttributeSize;
138138
private final int maxFormFields;
139+
private final int maxQueryParams;
139140
private final int maxFormBufferedSize;
140141
private final Http3Settings localSettings;
141142

@@ -145,6 +146,7 @@ public ConnectionHandler(io.vertx.core.net.QuicServer transport,
145146
boolean handle100ContinueAutomatically,
146147
int maxFormAttributeSize,
147148
int maxFormFields,
149+
int maxQueryParams,
148150
int maxFormBufferedSize,
149151
Http3Settings localSettings) {
150152
this.transport = transport;
@@ -153,6 +155,7 @@ public ConnectionHandler(io.vertx.core.net.QuicServer transport,
153155
this.handle100ContinueAutomatically = handle100ContinueAutomatically;
154156
this.maxFormAttributeSize = maxFormAttributeSize;
155157
this.maxFormFields = maxFormFields;
158+
this.maxQueryParams = maxQueryParams;
156159
this.maxFormBufferedSize = maxFormBufferedSize;
157160
this.localSettings = localSettings;
158161
}
@@ -174,7 +177,7 @@ public void handle(QuicConnection connection) {
174177
http3Connection.streamHandler(stream -> {
175178
HttpServerRequestImpl request = new HttpServerRequestImpl(requestHandler, stream, stream.context(),
176179
handle100ContinueAutomatically, maxFormAttributeSize,
177-
maxFormFields, maxFormBufferedSize, serverOrigin);
180+
maxFormFields, maxQueryParams, maxFormBufferedSize, serverOrigin);
178181
request.init();
179182
});
180183

@@ -218,7 +221,7 @@ public Future<HttpServer> listen(SocketAddress address) {
218221
}
219222

220223
quicServer.handler(new ConnectionHandler(quicServer, requestHandler, connectionHandler,
221-
config.isHandle100ContinueAutomatically(), config.getMaxFormAttributeSize(), config.getMaxFormFields(),
224+
config.isHandle100ContinueAutomatically(), config.getMaxFormAttributeSize(), config.getMaxFormFields(), config.getMaxQueryParams(),
222225
config.getMaxFormBufferedBytes(), http3Config.getInitialSettings() != null ? http3Config.getInitialSettings().copy() : new Http3Settings()));
223226
return quicServer
224227
.bind(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
@@ -64,6 +64,7 @@ public class HttpServerConnectionInitializer {
6464
private final boolean handle100ContinueAutomatically;
6565
private final int maxFormAttributeSize;
6666
private final int maxFormFields;
67+
private final int maxQueryParams;
6768
private final int maxFormBufferedBytes;
6869
private final Http1ServerConfig http1Config;
6970
private final Http2ServerConfig http2Config;
@@ -89,6 +90,7 @@ public HttpServerConnectionInitializer(ContextInternal context,
8990
boolean handle100ContinueAutomatically,
9091
int maxFormAttributeSize,
9192
int maxFormFields,
93+
int maxQueryParams,
9294
int maxFormBufferedBytes,
9395
Http1ServerConfig http1Config,
9496
Http2ServerConfig http2Config,
@@ -147,6 +149,7 @@ public HttpServerConnectionInitializer(ContextInternal context,
147149
this.handle100ContinueAutomatically = handle100ContinueAutomatically;
148150
this.maxFormAttributeSize = maxFormAttributeSize;
149151
this.maxFormFields = maxFormFields;
152+
this.maxQueryParams = maxQueryParams;
150153
this.maxFormBufferedBytes = maxFormBufferedBytes;
151154
this.http1Config = http1Config;
152155
this.http2Config = http2Config;
@@ -289,6 +292,7 @@ public void configureHttp1Handler(ChannelPipeline pipeline, SslContextManager ss
289292
sslContextManager,
290293
maxFormAttributeSize,
291294
maxFormFields,
295+
maxQueryParams,
292296
maxFormBufferedBytes,
293297
http1Config,
294298
registerWebSocketWriteHandlers,

0 commit comments

Comments
 (0)