GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Auto-port 5.0: Reject non-token characters in HTTP/2 header names (#1… · netty/netty@5015398

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http2/src
    • main/java/io/netty/handler/codec/http2
      • DefaultHttp2Headers.java
    • test/java/io/netty/handler/codec/http2
      • DefaultHttp2HeadersTest.java
      • InboundHttp2ToHttpAdapterTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Headers.java‎

Copy file name to clipboardExpand all lines: codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Headers.java
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ public void validateName(CharSequence name) {
5454
return;
5555
}
5656

57+
// RFC 9113 Section 8.2.1: HTTP/2 field names are valid HTTP/1.1 tokens (RFC 7230 Section 3.2.6)
58+
// with the additional constraint that they MUST be lowercase. Reject anything outside the token
59+
// grammar (non-ASCII, control characters, SP/HTAB, separators) before the lowercase check.
60+
int tokenIndex = HttpHeaderValidationUtil.validateToken(name);
61+
if (tokenIndex != -1) {
62+
PlatformDependent.throwException(connectionError(PROTOCOL_ERROR,
63+
"invalid header name [%s]", name));
64+
}
65+
5766
if (name instanceof AsciiString) {
5867
final int index;
5968
try {
Collapse file

‎codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2HeadersTest.java‎

Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2HeadersTest.java
+111Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,117 @@ public void execute() throws Throwable {
161161
});
162162
}
163163

164+
@Test
165+
public void rejectNonAsciiHeaderNameAsciiString() {
166+
// U+1F631 ("😱") encoded as F0 9F 98 B1 — bytes outside the token grammar that previously
167+
// slipped past the upper-case-only validator. See issue #11975.
168+
final byte[] buf = {(byte) 0xF0, (byte) 0x9F, (byte) 0x98, (byte) 0xB1};
169+
final Http2Headers headers = new DefaultHttp2Headers();
170+
assertThrows(Http2Exception.class, new Executable() {
171+
@Override
172+
public void execute() throws Throwable {
173+
headers.add(new AsciiString(buf), of("test"));
174+
}
175+
});
176+
}
177+
178+
@Test
179+
public void rejectNonAsciiHeaderNameCharSequence() {
180+
final Http2Headers headers = new DefaultHttp2Headers();
181+
assertThrows(Http2Exception.class, new Executable() {
182+
@Override
183+
public void execute() throws Throwable {
184+
// Non-ASCII char via the CharSequence path.
185+
headers.add("naÿme", "test");
186+
}
187+
});
188+
}
189+
190+
@Test
191+
public void rejectHighBitHeaderNameCharSequence() {
192+
final Http2Headers headers = new DefaultHttp2Headers();
193+
assertThrows(Http2Exception.class, new Executable() {
194+
@Override
195+
public void execute() throws Throwable {
196+
// U+0100 — above 0xFF, must be rejected by the CharSequence path.
197+
headers.add("naĀme", "test");
198+
}
199+
});
200+
}
201+
202+
@ParameterizedTest(name = "{displayName} [{index}] byte=0x{0}")
203+
@MethodSource("nonTokenBytesInHeaderName")
204+
void rejectNonTokenCharactersInHeaderName(int illegalByte) {
205+
final String name = "n" + (char) illegalByte + "ame";
206+
final Http2Headers headers = new DefaultHttp2Headers();
207+
assertThrows(Http2Exception.class, new Executable() {
208+
@Override
209+
public void execute() throws Throwable {
210+
headers.add(name, "test");
211+
}
212+
});
213+
}
214+
215+
static Stream<Arguments> nonTokenBytesInHeaderName() {
216+
return Stream.of(
217+
// Control characters: every byte in the C0 range that the previous validator silently let through.
218+
Arguments.of(0x00), // NUL
219+
Arguments.of(0x01), // SOH
220+
Arguments.of(0x07), // BEL
221+
Arguments.of(0x08), // BS
222+
Arguments.of(0x09), // HTAB
223+
Arguments.of(0x0A), // LF
224+
Arguments.of(0x0B), // VT
225+
Arguments.of(0x0C), // FF
226+
Arguments.of(0x0D), // CR
227+
Arguments.of(0x1F), // US
228+
Arguments.of(0x7F), // DEL
229+
// Whitespace and RFC 7230 separators that are not valid token characters.
230+
Arguments.of(0x20), // SP
231+
Arguments.of((int) ','),
232+
Arguments.of((int) ';'),
233+
Arguments.of((int) ':'),
234+
Arguments.of((int) '/'),
235+
Arguments.of((int) '='),
236+
Arguments.of((int) '?'),
237+
Arguments.of((int) '@'),
238+
Arguments.of((int) '('),
239+
Arguments.of((int) ')'),
240+
Arguments.of((int) '['),
241+
Arguments.of((int) ']'),
242+
Arguments.of((int) '{'),
243+
Arguments.of((int) '}'),
244+
Arguments.of((int) '<'),
245+
Arguments.of((int) '>'),
246+
Arguments.of((int) '\\'),
247+
Arguments.of((int) '"')
248+
);
249+
}
250+
251+
@Test
252+
public void acceptValidLowercaseTokenHeaderName() {
253+
// Regression: valid RFC 7230 token (lower-case ALPHA, DIGIT, "!#$%&'*+-.^_`|~") must be accepted.
254+
Http2Headers headers = new DefaultHttp2Headers();
255+
headers.add(of("x-custom-header"), of("v"));
256+
headers.add(of("2name"), of("v"));
257+
headers.add(of("a!#$%&'*+-.^_`|~b"), of("v"));
258+
assertTrue(headers.contains("x-custom-header"));
259+
assertTrue(headers.contains("2name"));
260+
assertTrue(headers.contains("a!#$%&'*+-.^_`|~b"));
261+
}
262+
263+
@Test
264+
public void acceptPseudoHeaderName() {
265+
// Regression: leading-colon pseudo-header names must remain accepted even though ":" is not a token char.
266+
Http2Headers headers = new DefaultHttp2Headers();
267+
headers.method(of("GET"));
268+
headers.path(of("/"));
269+
headers.scheme(of("https"));
270+
headers.authority(of("example.com"));
271+
assertEquals(of("GET"), headers.method());
272+
assertEquals(of("/"), headers.path());
273+
}
274+
164275
@Test
165276
public void testClearResetsPseudoHeaderDivision() {
166277
DefaultHttp2Headers http2Headers = new DefaultHttp2Headers();
Collapse file

‎codec-http2/src/test/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapterTest.java‎

Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapterTest.java
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ public void run() throws Http2Exception {
238238
@Test
239239
public void clientRequestSingleHeaderNonAsciiShouldThrow() throws Exception {
240240
boostrapEnv(1, 1, 1);
241-
final Http2Headers http2Headers = new DefaultHttp2Headers()
241+
// Disable validation on the client side so the non-ASCII header name reaches the wire; the
242+
// server-side validation (RFC 9113 §8.2.1 requires field names to be valid HTTP/1.1 tokens)
243+
// then rejects it, which surfaces as a stream error.
244+
final Http2Headers http2Headers = new DefaultHttp2Headers(false)
242245
.method(new AsciiString("GET"))
243246
.scheme(new AsciiString("https"))
244247
.authority(new AsciiString("example.org"))

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.