Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions java/org/apache/catalina/connector/Connector.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ public Connector(ProtocolHandler protocolHandler) {

/**
* The maximum number of locales that will be parsed for a request.
* Use a value less than zero for no limit. Defaults to 10.
* Use a value less than zero for no limit. Defaults to 20.
*/
private int maxLocaleCount = 10;
private int maxLocaleCount = 20;

/**
* The maximum number of parameters (GET plus POST) which will be automatically parsed by the container. 1000 by
Expand Down Expand Up @@ -526,8 +526,8 @@ public void setMaxCookieCount(int maxCookieCount) {


/**
* Returns the maximum number of locales that are permitted for a request. Requests that exceed this limit will be
* rejected when the locales are parsed. A value of less than zero means no limit.
* Returns the maximum number of locales that will be parsed for a request. A value of less than zero means no
* limit.
* @return the maximum locale count
*/
public int getMaxLocaleCount() {
Expand All @@ -536,8 +536,7 @@ public int getMaxLocaleCount() {


/**
* Sets the maximum number of locales that are permitted for a request. Requests that exceed this limit will be
* rejected when the locales are parsed. A value of less than zero means no limit.
* Sets the maximum number of locales that will be parsed for a request. A value of less than zero means no limit.
*
* @param maxLocaleCount the new maximum locale count
*/
Expand Down
2 changes: 1 addition & 1 deletion java/org/apache/catalina/connector/LocalStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ coyoteRequest.sendfileNotCanonical=Unable to determine canonical name of file [{
coyoteRequest.sessionCreateCommitted=Cannot create a session after the response has been committed
coyoteRequest.sessionEndAccessFail=Exception triggered ending access to session while recycling request
coyoteRequest.setAttribute.namenull=Cannot call setAttribute with a null name
coyoteRequest.tooManyLocales=More than the maximum allowed number of locales, [{0}], were detected. Use the maxLocaleCount attribute of the connector to resolve this if the application should accept more locales.
coyoteRequest.tooManyLocales=More than the maximum number of locales for a single request ([{0}]) were detected. Any locales beyond this limit have been ignored. To change this limit, set the maxLocaleCount attribute on the Connector.
coyoteRequest.trailersNotReady=It is illegal to call getTrailerFields() before isTrailerFieldsReady() has returned true
coyoteRequest.upgradeAfterAsync=Unable to upgrade the request because async processing has been started
coyoteRequest.upgradeAfterCommit=Unable to upgrade the request because the response has been committed
Expand Down
6 changes: 3 additions & 3 deletions java/org/apache/catalina/connector/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ public org.apache.coyote.Request getCoyoteRequest() {
private int maxPartHeaderSize = -1;

/**
* The maximum number of locales permitted for a request. The Accept-Language header value is untrusted input
* bounded only by the maximum header size so the number of locales is bounded by default to limit the
* The maximum number of locales that will be parsed for a request. The Accept-Language header value is untrusted
* input bounded only by the maximum header size so the number of locales is bounded by default to limit the
* per-request processing and the number of distinct locales exposed to web applications and internal components.
* A value of less than zero means no limit.
*/
Expand Down Expand Up @@ -3183,7 +3183,7 @@ protected void parseLocalesHeader(String value, TreeMap<Double,ArrayList<Locale>

// Determine how many more entries are of interest. One more than the
// maximum is parsed so that a header that exceeds the limit is
// rejected rather than silently truncated. Parsing no further entries
// logged rather than silently truncated. Parsing no further entries
// once the limit is reached avoids creating Locale objects for entries
// that can never be used.
int maxElements = -1;
Expand Down
2 changes: 1 addition & 1 deletion java/org/apache/catalina/connector/mbeans-descriptors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
type="int"/>

<attribute name="maxLocaleCount"
description="The maximum number of locales that are parsed for a request. 10 by default. A value of less than 0 means no limit."
description="The maximum number of locales that are parsed for a request. 20 by default. A value of less than 0 means no limit."
type="int"/>

<attribute name="maxParameterCount"
Expand Down
18 changes: 9 additions & 9 deletions test/org/apache/catalina/connector/TestRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,8 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
*/
@Test
public void testAcceptLanguageLocaleLimitConfigurable() throws Exception {
// Connector default of 10 permits exactly 10 locales
Assert.assertEquals(10, localeCount(new Connector(), buildAcceptLanguage(10)));
// Connector default of 20 permits exactly 20 locales
Assert.assertEquals(20, localeCount(new Connector(), buildAcceptLanguage(20)));

// Explicit limit is enforced
Connector connector = new Connector();
Expand All @@ -809,7 +809,7 @@ public void testAcceptLanguageLocaleLimitConfigurable() throws Exception {
// No limit
connector = new Connector();
connector.setMaxLocaleCount(-1);
Assert.assertEquals(20, localeCount(connector, buildAcceptLanguage(20)));
Assert.assertEquals(30, localeCount(connector, buildAcceptLanguage(30)));
}

private static String buildAcceptLanguage(int localeCount) {
Expand Down Expand Up @@ -844,13 +844,13 @@ private static int localeCount(Connector connector, String acceptLanguage) {
*/
@Test
public void testAcceptLanguageLocaleLimitMultipleHeaders() throws Exception {
// 5 + 5 = 10, within the default limit
Assert.assertEquals(10, localeCount(new Connector(), "aa-000,aa-001,aa-002,aa-003,aa-004",
"aa-005,aa-006,aa-007,aa-008,aa-009"));
// 10 + 10 = 20, within the default limit
Assert.assertEquals(20, localeCount(new Connector(), buildAcceptLanguage(10),
buildAcceptLanguage(10)));

// 5 + 6 = 11, exceeds the default limit
Assert.assertEquals(10, localeCount(new Connector(), "aa-000,aa-001,aa-002,aa-003,aa-004",
"aa-005,aa-006,aa-007,aa-008,aa-009,aa-010"));
// 10 + 11 = 21, exceeds the default limit
Assert.assertEquals(20, localeCount(new Connector(), buildAcceptLanguage(10),
buildAcceptLanguage(11)));
}

private static int localeCount(Connector connector, String... acceptLanguages) {
Expand Down
4 changes: 4 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@
one space was required. Pull request <pr>1148</pr> provided by Arturo
Bernal. (markt)
</fix>
<update>
Increase the default value of the <code>maxLocaleCount</code> attribute
of the <code>Connector</code> from 10 to 20.
</update>
</changelog>
</subsection>
<subsection name="Coyote">
Expand Down
4 changes: 2 additions & 2 deletions webapps/docs/config/ajp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@

<attribute name="maxLocaleCount" required="false">
<p>The maximum number of locales (obtained from the
<code>Accept-Language</code> header(s)) that are permitted for a request.
<code>Accept-Language</code> header(s)) that will be parsed for a request.
Locales above this limit will be ignored when the locales are
parsed and an info will be logged. A value of less than 0 means no
limit. If not specified, a default of 10 is used.</p>
limit. If not specified, a default of 20 is used.</p>
</attribute>

<attribute name="maxParameterCount" required="false">
Expand Down
4 changes: 2 additions & 2 deletions webapps/docs/config/http.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@

<attribute name="maxLocaleCount" required="false">
<p>The maximum number of locales (obtained from the
<code>Accept-Language</code> header(s)) that are permitted for a request.
<code>Accept-Language</code> header(s)) that will be parsed for a request.
Locales above this limit will be ignored when the locales are
parsed and an info will be logged. A value of less than 0 means no
limit. If not specified, a default of 10 is used.</p>
limit. If not specified, a default of 20 is used.</p>
</attribute>

<attribute name="maxParameterCount" required="false">
Expand Down