Skip to content

Commit 99c743c

Browse files
Merge pull request #8008 from eclipse/jetty-10.0.x-legacyMultipartParser
Add compliance mode for LEGACY multipart parser in Jetty 10+
2 parents b274a3c + a61f145 commit 99c743c

File tree

11 files changed

+1436
-38
lines changed

11 files changed

+1436
-38
lines changed

jetty-server/src/main/config/etc/jetty.xml

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<Set name="uriCompliance"><Call class="org.eclipse.jetty.http.UriCompliance" name="from"><Arg><Property name="jetty.httpConfig.uriCompliance" default="SAFE"/></Arg></Call></Set>
7676
<Set name="requestCookieCompliance"><Call class="org.eclipse.jetty.http.CookieCompliance" name="valueOf"><Arg><Property name="jetty.httpConfig.requestCookieCompliance" default="RFC6265"/></Arg></Call></Set>
7777
<Set name="responseCookieCompliance"><Call class="org.eclipse.jetty.http.CookieCompliance" name="valueOf"><Arg><Property name="jetty.httpConfig.responseCookieCompliance" default="RFC6265"/></Arg></Call></Set>
78+
<Set name="multiPartFormDataCompliance"><Call class="org.eclipse.jetty.server.MultiPartFormDataCompliance" name="valueOf"><Arg><Property name="jetty.httpConfig.multiPartFormDataCompliance" default="RFC7578"/></Arg></Call></Set>
7879
<Set name="relativeRedirectAllowed"><Property name="jetty.httpConfig.relativeRedirectAllowed" default="false"/></Set>
7980
<Set name="useInputDirectByteBuffers" property="jetty.httpConfig.useInputDirectByteBuffers"/>
8081
<Set name="useOutputDirectByteBuffers" property="jetty.httpConfig.useOutputDirectByteBuffers"/>

jetty-server/src/main/config/modules/server.mod

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ etc/jetty.xml
8282
# jetty.httpConfig.responseCookieCompliance=RFC6265
8383
# end::documentation-server-compliance[]
8484

85+
## multipart/form-data compliance mode of: LEGACY(slow), RFC7578(fast)
86+
# jetty.httpConfig.multiPartFormDataCompliance=RFC7578
87+
8588
# tag::documentation-server-config[]
8689
### Server configuration
8790
## Whether ctrl+c on the console gracefully stops the Jetty server

jetty-server/src/main/java/org/eclipse/jetty/server/HttpConfiguration.java

+16
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public class HttpConfiguration implements Dumpable
7575
private UriCompliance _uriCompliance = UriCompliance.DEFAULT;
7676
private CookieCompliance _requestCookieCompliance = CookieCompliance.RFC6265;
7777
private CookieCompliance _responseCookieCompliance = CookieCompliance.RFC6265;
78+
private MultiPartFormDataCompliance _multiPartCompliance = MultiPartFormDataCompliance.RFC7578;
7879
private boolean _notifyRemoteAsyncErrors = true;
7980
private boolean _relativeRedirectAllowed;
8081
private HostPort _serverAuthority;
@@ -625,6 +626,21 @@ public void setResponseCookieCompliance(CookieCompliance cookieCompliance)
625626
_responseCookieCompliance = cookieCompliance == null ? CookieCompliance.RFC6265 : cookieCompliance;
626627
}
627628

629+
/**
630+
* Sets the compliance level for multipart/form-data handling.
631+
*
632+
* @param multiPartCompliance The multipart/form-data compliance level.
633+
*/
634+
public void setMultiPartFormDataCompliance(MultiPartFormDataCompliance multiPartCompliance)
635+
{
636+
_multiPartCompliance = multiPartCompliance == null ? MultiPartFormDataCompliance.RFC7578 : multiPartCompliance;
637+
}
638+
639+
public MultiPartFormDataCompliance getMultipartFormDataCompliance()
640+
{
641+
return _multiPartCompliance;
642+
}
643+
628644
/**
629645
* @param notifyRemoteAsyncErrors whether remote errors, when detected, are notified to async applications
630646
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// ========================================================================
3+
// Copyright (c) 1995-2022 Mort Bay Consulting Pty Ltd and others.
4+
//
5+
// This program and the accompanying materials are made available under the
6+
// terms of the Eclipse Public License v. 2.0 which is available at
7+
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
8+
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
9+
//
10+
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
11+
// ========================================================================
12+
//
13+
14+
package org.eclipse.jetty.server;
15+
16+
/**
17+
* The compliance level for parsing <code>multiPart/form-data</code>
18+
*/
19+
public enum MultiPartFormDataCompliance
20+
{
21+
/**
22+
* Legacy <code>multiPart/form-data</code> parsing which is slow but forgiving.
23+
* It will accept non-compliant preambles and inconsistent line termination.
24+
*
25+
* @see org.eclipse.jetty.server.MultiPartInputStreamParser
26+
*/
27+
LEGACY,
28+
/**
29+
* RFC7578 compliant parsing that is a fast but strict parser.
30+
*
31+
* @see org.eclipse.jetty.server.MultiPartFormInputStream
32+
*/
33+
RFC7578
34+
}

jetty-server/src/main/java/org/eclipse/jetty/server/MultiPartFormInputStream.java

+1-17
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import javax.servlet.ServletInputStream;
3838
import javax.servlet.http.Part;
3939

40+
import org.eclipse.jetty.server.MultiParts.NonCompliance;
4041
import org.eclipse.jetty.util.BufferUtil;
4142
import org.eclipse.jetty.util.ByteArrayOutputStream2;
4243
import org.eclipse.jetty.util.MultiException;
@@ -104,23 +105,6 @@ private enum State
104105
private volatile int _bufferSize = 16 * 1024;
105106
private State state = State.UNPARSED;
106107

107-
public enum NonCompliance
108-
{
109-
TRANSFER_ENCODING("https://tools.ietf.org/html/rfc7578#section-4.7");
110-
111-
final String _rfcRef;
112-
113-
NonCompliance(String rfcRef)
114-
{
115-
_rfcRef = rfcRef;
116-
}
117-
118-
public String getURL()
119-
{
120-
return _rfcRef;
121-
}
122-
}
123-
124108
/**
125109
* @return an EnumSet of non compliances with the RFC that were accepted by this parser
126110
*/

0 commit comments

Comments
 (0)