-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12560 from jetty/jetty-12.0.x-FormLimitDocs
Add documentation for form limits & improve configuration via context attributes
- Loading branch information
Showing
10 changed files
with
262 additions
and
9 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...les/code/examples/src/main/java/org/eclipse/jetty/docs/programming/security/FormDocs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.docs.programming.security; | ||
|
||
import org.eclipse.jetty.ee10.servlet.ServletContextHandler; | ||
import org.eclipse.jetty.server.FormFields; | ||
import org.eclipse.jetty.server.Request; | ||
import org.eclipse.jetty.util.Fields; | ||
|
||
public class FormDocs | ||
{ | ||
public void limitFormContent() | ||
{ | ||
ServletContextHandler servletContextHandler = new ServletContextHandler(); | ||
// tag::limitFormContent[] | ||
int maxFormKeys = 100; | ||
int maxFormSizeInBytes = 1024; | ||
servletContextHandler.setMaxFormContentSize(maxFormSizeInBytes); | ||
servletContextHandler.setMaxFormKeys(maxFormKeys); | ||
// end::limitFormContent[] | ||
} | ||
|
||
public void jettyCoreAPI() | ||
{ | ||
Request request = null; | ||
// tag::jettyCoreAPI[] | ||
int maxFormKeys = 100; | ||
int maxFormSizeInBytes = 1024; | ||
Fields fields; | ||
|
||
// Explicit set the form limits. | ||
fields = FormFields.getFields(request, maxFormKeys, maxFormSizeInBytes); | ||
|
||
// Rely on default form limits. | ||
fields = FormFields.getFields(request); | ||
// end::jettyCoreAPI[] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...tation/jetty/modules/operations-guide/pages/security/configuring-form-size.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
[[limit-form-content]] | ||
= Limiting Form Content | ||
|
||
Forms can be a vector for denial-of-service attacks, like explained in xref:programming-guide:security/configuring-form-size.adoc[this section] of the Programming Guide. | ||
|
||
== Configuring Form Limits for a Web Application | ||
|
||
To configure the form limits for a single web application, the `WebAppContext` instance can be configured from a context XML file or `WEB-INF/jetty-web.xml` file: | ||
|
||
[,xml,subs=attributes+] | ||
---- | ||
<Configure class="org.eclipse.jetty.{ee-current}.webapp.WebAppContext"> | ||
... | ||
<Set name="maxFormContentSize">200000</Set> | ||
<Set name="maxFormKeys">200</Set> | ||
</Configure> | ||
---- | ||
|
||
These settings can also be set via the following `ServletContext` attributes. | ||
|
||
- `org.eclipse.jetty.server.Request.maxFormKeys` | ||
- `org.eclipse.jetty.server.Request.maxFormContentSize` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...ation/jetty/modules/programming-guide/pages/security/configuring-form-size.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
[[limit-form-content]] | ||
= Limiting Form Content | ||
|
||
Form content sent to the server is processed by Jetty into a map of parameters to be used by the web application. | ||
Forms can be a vector for denial-of-service attacks, since significant memory and CPU can be consumed if a malicious client sends very large form content or a large number of form keys. | ||
Thus, Jetty limits the amount of data and keys that can be in a form posted to Jetty. | ||
|
||
The default maximum size Jetty permits is 200000 bytes and 1000 keys. | ||
You can change this default for a particular web application or for all web applications on a particular `Server` instance. | ||
|
||
== Configuring Form Limits for a Web Application | ||
|
||
To configure the form limits for a single web application, the `ServletContextHandler` (or `WebAppContext`) instance can be configured using the following methods: | ||
|
||
[,java,indent=0] | ||
---- | ||
include::code:example$src/main/java/org/eclipse/jetty/docs/programming/security/FormDocs.java[tags=limitFormContent] | ||
---- | ||
|
||
These settings can also be set via the following `ServletContext` attributes. | ||
|
||
- `org.eclipse.jetty.server.Request.maxFormKeys` | ||
- `org.eclipse.jetty.server.Request.maxFormContentSize` | ||
|
||
== Configuring Default Form Limits for the Server | ||
|
||
The following system properties can be used to configure form limits for the entire server, including all contexts without explicit configuration: | ||
|
||
- `org.eclipse.jetty.server.Request.maxFormKeys` | ||
- `org.eclipse.jetty.server.Request.maxFormContentSize`. | ||
|
||
If not configured for either the server or a specific context, then the default `maxFormKeys` is 1000 and the default `maxFormContentSize` is 200000. | ||
|
||
== Limiting Form Content with Jetty Core API | ||
|
||
The class `FormFields` is used to parse forms with the Jetty Core API, which provides `onFields` and `getFields` static methods to provide both async & blocking ways to parse a form. | ||
|
||
These methods can take parameters for `maxFields` and `maxLength` which can be used to limit the form content. | ||
|
||
[,java,indent=0] | ||
---- | ||
include::code:example$src/main/java/org/eclipse/jetty/docs/programming/security/FormDocs.java[tags=jettyCoreAPI] | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters