|
30 | 30 | import org.apache.coyote.http11.InputFilter; |
31 | 31 | import org.apache.tomcat.util.buf.ByteChunk; |
32 | 32 | import org.apache.tomcat.util.buf.HexUtils; |
| 33 | +import org.apache.tomcat.util.http.parser.HttpParser; |
33 | 34 | import org.apache.tomcat.util.net.ApplicationBufferHandler; |
34 | 35 | import org.apache.tomcat.util.res.StringManager; |
35 | 36 |
|
@@ -443,6 +444,13 @@ protected void parseEndChunk() throws IOException { |
443 | 444 |
|
444 | 445 | private boolean parseHeader() throws IOException { |
445 | 446 |
|
| 447 | + /* |
| 448 | + * Implementation note: Any changes to this method probably need to be echoed in |
| 449 | + * Http11InputBuffer.parseHeader(). Why not use a common implementation? In short, this code uses blocking |
| 450 | + * reads whereas Http11InputBuffer using non-blocking reads. The code is just different enough that a common |
| 451 | + * implementation wasn't viewed as practical. |
| 452 | + */ |
| 453 | + |
446 | 454 | Map<String,String> headers = request.getTrailerFields(); |
447 | 455 |
|
448 | 456 | byte chr = 0; |
@@ -489,6 +497,9 @@ private boolean parseHeader() throws IOException { |
489 | 497 |
|
490 | 498 | if (chr == Constants.COLON) { |
491 | 499 | colon = true; |
| 500 | + } else if (!HttpParser.isToken(chr)) { |
| 501 | + // Non-token characters are illegal in header names |
| 502 | + throw new IOException(sm.getString("chunkedInputFilter.invalidTrailerHeaderName")); |
492 | 503 | } else { |
493 | 504 | trailingHeaders.append(chr); |
494 | 505 | } |
@@ -550,7 +561,9 @@ private boolean parseHeader() throws IOException { |
550 | 561 | if (chr == Constants.CR || chr == Constants.LF) { |
551 | 562 | parseCRLF(true); |
552 | 563 | eol = true; |
553 | | - } else if (chr == Constants.SP) { |
| 564 | + } else if (HttpParser.isControl(chr) && chr != Constants.HT) { |
| 565 | + throw new IOException(sm.getString("chunkedInputFilter.invalidTrailerHeaderValue")); |
| 566 | + } else if (chr == Constants.SP || chr == Constants.HT) { |
554 | 567 | trailingHeaders.append(chr); |
555 | 568 | } else { |
556 | 569 | trailingHeaders.append(chr); |
|
0 commit comments