// HTTP header contents
responseHeaderMessage.appendInt(response.getStatus());
String message = null;
- if (org.apache.coyote.Constants.USE_CUSTOM_STATUS_MSG_IN_HEADER) {
+ if (org.apache.coyote.Constants.USE_CUSTOM_STATUS_MSG_IN_HEADER &&
+ HttpMessages.isSafeInHttpHeader(response.getMessage())) {
message = response.getMessage();
}
if (message == null){
message = HttpMessages.getMessage(response.getStatus());
- } else {
- message = message.replace('\n', ' ').replace('\r', ' ');
}
if (message == null) {
// mod_jk + httpd 2.x fails with a null status message - bug 45026
// HTTP header contents
responseHeaderMessage.appendInt(response.getStatus());
String message = null;
- if (org.apache.coyote.Constants.USE_CUSTOM_STATUS_MSG_IN_HEADER) {
+ if (org.apache.coyote.Constants.USE_CUSTOM_STATUS_MSG_IN_HEADER &&
+ HttpMessages.isSafeInHttpHeader(response.getMessage())) {
message = response.getMessage();
}
if (message == null){
message = HttpMessages.getMessage(response.getStatus());
- } else {
- message = message.replace('\n', ' ').replace('\r', ' ');
}
if (message == null) {
// mod_jk + httpd 2.x fails with a null status message - bug 45026
// Write message
String message = null;
- if (org.apache.coyote.Constants.USE_CUSTOM_STATUS_MSG_IN_HEADER) {
+ if (org.apache.coyote.Constants.USE_CUSTOM_STATUS_MSG_IN_HEADER &&
+ HttpMessages.isSafeInHttpHeader(response.getMessage())) {
message = response.getMessage();
}
if (message == null) {
write(HttpMessages.getMessage(status));
} else {
- write(message.replace('\n', ' ').replace('\r', ' '));
+ write(message);
}
// End the response status line
// Write message
String message = null;
- if (org.apache.coyote.Constants.USE_CUSTOM_STATUS_MSG_IN_HEADER) {
+ if (org.apache.coyote.Constants.USE_CUSTOM_STATUS_MSG_IN_HEADER &&
+ HttpMessages.isSafeInHttpHeader(response.getMessage())) {
message = response.getMessage();
}
if (message == null) {
write(HttpMessages.getMessage(status));
} else {
- write(message.replace('\n', ' ').replace('\r', ' '));
+ write(message);
}
// End the response status line
return (result.toString());
}
+ /**
+ * Is the provided message safe to use in an HTTP header. Safe messages must
+ * meet the requirements of RFC2616 - i.e. must consist only of TEXT.
+ *
+ * @param msg The message to test
+ * @return <code>true</code> if the message is safe to use in an HTTP
+ * header else <code>false</code>
+ */
+ public static boolean isSafeInHttpHeader(String msg) {
+ // Nulls are fine. It is up to the calling code to address any NPE
+ // concerns
+ if (msg == null) {
+ return true;
+ }
+
+ // TEXT is defined as OCTET excpet CTLs
+ // OCTET is defined as an 8-bit sequence of data
+ // CTL is defined as octets 0-31 and 127
+ for (char c : msg.toCharArray()) {
+ if (c > 255 || c < 32 || c == 127) {
+ return false;
+ }
+ }
+
+ return true;
+ }
}
# See the License for the specific language governing permissions and
# limitations under the License.
-# HttpMessages
+# HttpMessages. The values in this file will be used in HTTP headers and as such
+# may only contain TEXT as defined by RFC 2616
sc.100=Continue
sc.101=Switching Protocols
sc.200=OK
# See the License for the specific language governing permissions and
# limitations under the License.
-# HttpMessages
+# HttpMessages. The values in this file will be used in HTTP headers and as such
+# may only contain TEXT as defined by RFC 2616
sc.100=Continuar
sc.101=Cambiando Protocolos
sc.200=OK
# See the License for the specific language governing permissions and
# limitations under the License.
+# HttpMessages. The values in this file will be used in HTTP headers and as such
+# may only contain TEXT as defined by RFC 2616
sc.100=Continuer
sc.101=Changement de Protocols
sc.200=OK
--- /dev/null
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# HttpMessages. The values in this file will be used in HTTP headers and as such
+# may only contain TEXT as defined by RFC 2616. Since Japanese language messages
+# do not meet this requirement, English text is used.
+sc.100=Continue
+sc.101=Switching Protocols
+sc.200=OK
+sc.201=Created
+sc.202=Accepted
+sc.203=Non-Authoritative Information
+sc.204=No Content
+sc.205=Reset Content
+sc.206=Partial Content
+sc.207=Multi-Status
+sc.300=Multiple Choices
+sc.301=Moved Permanently
+sc.302=Moved Temporarily
+sc.303=See Other
+sc.304=Not Modified
+sc.305=Use Proxy
+sc.307=Temporary Redirect
+sc.400=Bad Request
+sc.401=Unauthorized
+sc.402=Payment Required
+sc.403=Forbidden
+sc.404=Not Found
+sc.405=Method Not Allowed
+sc.406=Not Acceptable
+sc.407=Proxy Authentication Required
+sc.408=Request Timeout
+sc.409=Conflict
+sc.410=Gone
+sc.411=Length Required
+sc.412=Precondition Failed
+sc.413=Request Entity Too Large
+sc.414=Request-URI Too Long
+sc.415=Unsupported Media Type
+sc.416=Requested Range Not Satisfiable
+sc.417=Expectation Failed
+sc.422=Unprocessable Entity
+sc.423=Locked
+sc.424=Failed Dependency
+sc.500=Internal Server Error
+sc.501=Not Implemented
+sc.502=Bad Gateway
+sc.503=Service Unavailable
+sc.504=Gateway Timeout
+sc.505=HTTP Version Not Supported
+sc.507=Insufficient Storage
<property
name="org.apache.coyote. USE_CUSTOM_STATUS_MSG_IN_HEADER"><p>If this is
<code>true</code> custom HTTP status messages will be used within HTTP
- headers. Users must ensure that any such message is ISO-8859-1 encoded,
- particularly if user provided input is included in the message, to prevent
- a possible XSS vulnerability. If not specified the default value of
+ headers. If a custom message is specified that is not valid for use in an
+ HTTP header (as defined by RFC2616) then the custom message will be
+ ignored and the default message used. Note that there is some overhead
+ associated with the additional checking that is performed when custom
+ messages are used. If not specified the default value of
<code>false</code> will be used.</p>
</property>