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 — Reject non-token characters in HTTP/2 header names by daguimu · Pull Request #16762 · netty/netty

Reject non-token characters in HTTP/2 header names #16762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
normanmaurer merged 3 commits into netty:4.2 from daguimu:fix/http2-header-name-token-validation-11975
Jun 30, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Reject non-token characters in HTTP/2 header names #16762

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
e4612ec
Reject non-token characters in HTTP/2 header names
daguimu May 7, 2026
b2e186b
Merge branch '4.2' into fix/http2-header-name-token-validation-11975
normanmaurer Jun 18, 2026
4d36ccf
Address review: keep the non-ASCII header test end-to-end, drop dupli…
daguimu Jun 21, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

Some comments aren't visible on the classic Files Changed page.

There are no files selected for viewing

9 changes: 9 additions & 0 deletions 9 codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Headers.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ public void validateName(CharSequence name) {
return;
}

// RFC 9113 Section 8.2.1: HTTP/2 field names are valid HTTP/1.1 tokens (RFC 7230 Section 3.2.6)
Comment thread

@bryce-anderson bryce-anderson Jun 22, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the RFC reference on the public DefaultHttp2Headers(boolean validate) constructor? I think we're not technically following RFC 7230 since we do not allow upper case characters.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
// with the additional constraint that they MUST be lowercase. Reject anything outside the token
// grammar (non-ASCII, control characters, SP/HTAB, separators) before the lowercase check.
int tokenIndex = HttpHeaderValidationUtil.validateToken(name);
if (tokenIndex != -1) {
PlatformDependent.throwException(connectionError(PROTOCOL_ERROR,
"invalid header name [%s]", name));
}
Comment thread

@normanmaurer normanmaurer Jun 18, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a stream error ?


8.1.1.  Malformed Messages

   A malformed request or response is one that is an otherwise valid
   sequence of HTTP/2 frames but is invalid due to the presence of
   extraneous frames, prohibited fields or pseudo-header fields, the
   absence of mandatory pseudo-header fields, the inclusion of uppercase
   field names, or invalid field names and/or values (in certain
   circumstances; see Section 8.2).

   A request or response that includes message content can include a
   content-length header field.  A request or response is also malformed
   if the value of a content-length header field does not equal the sum
   of the DATA frame payload lengths that form the content, unless the
   message is defined as having no content.  For example, 204 or 304
   responses contain no content, as does the response to a HEAD request.
   A response that is defined to have no content, as described in
   Section 6.4.1 of [HTTP], MAY have a non-zero content-length header
   field, even though no content is included in DATA frames.

   Intermediaries that process HTTP requests or responses (i.e., any
   intermediary not acting as a tunnel) MUST NOT forward a malformed
   request or response.  Malformed requests or responses that are
   detected MUST be treated as a stream error (Section 5.4.2) of type
   PROTOCOL_ERROR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@chrisvest chrisvest Jun 21, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The connection errors thrown from here (all the other checks also throw connection error) are caught in HpackDecoder.appendToHeaderList and converted into stream errors.

I agree it's pretty confusing that we handle validation errors in this way.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@normanmaurer normanmaurer Jun 22, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we still throw this as a stream error so it is not as confusing or at least add a comment... The former would be preferred imho

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

if (name instanceof AsciiString) {
final int index;
try {
Expand Down
111 changes: 111 additions & 0 deletions 111 codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2HeadersTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,117 @@ public void execute() throws Throwable {
});
}

@Test
public void rejectNonAsciiHeaderNameAsciiString() {
// U+1F631 ("😱") encoded as F0 9F 98 B1 — bytes outside the token grammar that previously
// slipped past the upper-case-only validator. See issue #11975.
final byte[] buf = {(byte) 0xF0, (byte) 0x9F, (byte) 0x98, (byte) 0xB1};
final Http2Headers headers = new DefaultHttp2Headers();
assertThrows(Http2Exception.class, new Executable() {
@Override
public void execute() throws Throwable {
headers.add(new AsciiString(buf), of("test"));
}
});
}

@Test
public void rejectNonAsciiHeaderNameCharSequence() {
final Http2Headers headers = new DefaultHttp2Headers();
assertThrows(Http2Exception.class, new Executable() {
@Override
public void execute() throws Throwable {
// Non-ASCII char via the CharSequence path.
headers.add("naÿme", "test");
}
});
}

@Test
public void rejectHighBitHeaderNameCharSequence() {
final Http2Headers headers = new DefaultHttp2Headers();
assertThrows(Http2Exception.class, new Executable() {
@Override
public void execute() throws Throwable {
// U+0100 — above 0xFF, must be rejected by the CharSequence path.
headers.add("naĀme", "test");
}
});
}

@ParameterizedTest(name = "{displayName} [{index}] byte=0x{0}")
@MethodSource("nonTokenBytesInHeaderName")
void rejectNonTokenCharactersInHeaderName(int illegalByte) {
final String name = "n" + (char) illegalByte + "ame";
final Http2Headers headers = new DefaultHttp2Headers();
assertThrows(Http2Exception.class, new Executable() {
@Override
public void execute() throws Throwable {
headers.add(name, "test");
}
});
}

static Stream<Arguments> nonTokenBytesInHeaderName() {
return Stream.of(
// Control characters: every byte in the C0 range that the previous validator silently let through.
Arguments.of(0x00), // NUL
Arguments.of(0x01), // SOH
Arguments.of(0x07), // BEL
Arguments.of(0x08), // BS
Arguments.of(0x09), // HTAB
Arguments.of(0x0A), // LF
Arguments.of(0x0B), // VT
Arguments.of(0x0C), // FF
Arguments.of(0x0D), // CR
Arguments.of(0x1F), // US
Arguments.of(0x7F), // DEL
// Whitespace and RFC 7230 separators that are not valid token characters.
Arguments.of(0x20), // SP
Arguments.of((int) ','),
Arguments.of((int) ';'),
Arguments.of((int) ':'),
Arguments.of((int) '/'),
Arguments.of((int) '='),
Arguments.of((int) '?'),
Arguments.of((int) '@'),
Arguments.of((int) '('),
Arguments.of((int) ')'),
Arguments.of((int) '['),
Arguments.of((int) ']'),
Arguments.of((int) '{'),
Arguments.of((int) '}'),
Arguments.of((int) '<'),
Arguments.of((int) '>'),
Arguments.of((int) '\\'),
Arguments.of((int) '"')
);
}

@Test
public void acceptValidLowercaseTokenHeaderName() {
// Regression: valid RFC 7230 token (lower-case ALPHA, DIGIT, "!#$%&'*+-.^_`|~") must be accepted.
Http2Headers headers = new DefaultHttp2Headers();
headers.add(of("x-custom-header"), of("v"));
headers.add(of("2name"), of("v"));
headers.add(of("a!#$%&'*+-.^_`|~b"), of("v"));
assertTrue(headers.contains("x-custom-header"));
assertTrue(headers.contains("2name"));
assertTrue(headers.contains("a!#$%&'*+-.^_`|~b"));
}

@Test
public void acceptPseudoHeaderName() {
// Regression: leading-colon pseudo-header names must remain accepted even though ":" is not a token char.
Http2Headers headers = new DefaultHttp2Headers();
headers.method(of("GET"));
headers.path(of("/"));
headers.scheme(of("https"));
headers.authority(of("example.com"));
assertEquals(of("GET"), headers.method());
assertEquals(of("/"), headers.path());
}

@Test
public void testClearResetsPseudoHeaderDivision() {
DefaultHttp2Headers http2Headers = new DefaultHttp2Headers();
Expand Down
5 changes: 4 additions & 1 deletion 5 codec-http2/src/test/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapterTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ public void run() throws Http2Exception {
@Test
public void clientRequestSingleHeaderNonAsciiShouldThrow() throws Exception {
boostrapEnv(1, 1, 1);
final Http2Headers http2Headers = new DefaultHttp2Headers()
// Disable validation on the client side so the non-ASCII header name reaches the wire; the
// server-side validation (RFC 9113 §8.2.1 requires field names to be valid HTTP/1.1 tokens)
// then rejects it, which surfaces as a stream error.
final Http2Headers http2Headers = new DefaultHttp2Headers(false)
.method(new AsciiString("GET"))
.scheme(new AsciiString("https"))
.authority(new AsciiString("example.org"))
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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.