Skip to content

Commit

Permalink
Revert "HttpHeaderValidationUtil should reject chars past the 1 byte …
Browse files Browse the repository at this point in the history
…range" (netty#13615)

Motivation:
[RFC 9110 Section
5.5-4](https://datatracker.ietf.org/doc/html/rfc9110#section-5.5-4) says
we _should_ constrain ourselves to only putting US-ASCII in header
values, _but_ encodings beyond that are technically allowed as long as
they are ASCII-compatible (e.g. ISO-8859-1 or UTF-8).
In such a case, some of their characters will fall into the "obs-text"
clause.

One complication with our header validation is that we don't at that
point know if we're the recipient or the sender.
And we also don't at that point know what encoding is used.

The Netty header encoder clobbers non-ASCII characters, but people may
have custom header encoders that permit more characters.

Modification:
This reverts netty#13541, so we no longer enforce that `String` header values
only contain US-ASCII characters.

Result:
Restore the "support" for non-ASCII header encodings that we had
previously.
  • Loading branch information
chrisvest authored Sep 18, 2023
1 parent 6cb6d38 commit 709137e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ private static int verifyValidHeaderValueCharSequence(CharSequence value) {
// See: https://datatracker.ietf.org/doc/html/rfc7230#section-3.2
// And: https://datatracker.ietf.org/doc/html/rfc5234#appendix-B.1
int b = value.charAt(0);
if (b < 0x21 || b == 0x7F || 0xFF < b) {
if (b < 0x21 || b == 0x7F) {
return 0;
}
int length = value.length();
for (int i = 1; i < length; i++) {
b = value.charAt(i);
if (b < 0x20 && b != 0x09 || b == 0x7F || 0xFF < b) {
if (b < 0x20 && b != 0x09 || b == 0x7F) {
return i;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,6 @@ void decodingInvalidHeaderValuesMustFailIfFirstCharIsIllegalCharSequence(AsciiSt
assertEquals(0, validateValidHeaderValue(asCharSequence(value)));
}

@Test
void decodingInvalidHeaderValuesMustFailIfFirstCharIsIllegalAsciiString() {
assertEquals(0, validateValidHeaderValue("" + (char) (0xFF + 1)));
}

public static List<AsciiString> legalFirstChar() {
List<AsciiString> list = new ArrayList<AsciiString>();

Expand Down Expand Up @@ -291,11 +286,6 @@ void decodingInvalidHeaderValuesMustFailIfNotFirstCharIsIllegalCharSequence(Asci
assertEquals(1, validateValidHeaderValue(asCharSequence(value)));
}

@Test
void decodingInvalidHeaderValuesMustFailIfNotFirstCharIsIllegalCharSequence() {
assertEquals(1, validateValidHeaderValue("a" + (char) (0xFF + 1)));
}

public static List<AsciiString> legalNotFirstChar() {
List<AsciiString> list = new ArrayList<AsciiString>();

Expand Down

0 comments on commit 709137e

Please sign in to comment.