Forbidden inbound frames on reserved streams are not connection PROTOCOL_ERROR

Open
#17,427 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
java
Domain
networking

Research direction

Start with the reserved-stream state handling in codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java and compare it with the flow-controller paths in DefaultHttp2LocalFlowController.java. Review Http2ConnectionHandler.java and the ReservedLocalDataProbe behavior, then verify that forbidden inbound frames on both reserved states consistently produce a connection-level PROTOCOL_ERROR before flow-control or listener handling.

Written by the indexing model from the issue text.

Description

Summary

RFC 9113 requires forbidden frames received on reserved streams to be treated as connection errors of type PROTOCOL_ERROR. Netty does not consistently produce that result. For RESERVED_LOCAL, DATA can throw UnsupportedOperationException or become a stream-level PROTOCOL_ERROR; for RESERVED_REMOTE, forbidden inbound frames such as WINDOW_UPDATE can be accepted or mapped through non-HTTP/2 exception paths.

Standard Requirement

Official standard: RFC 9113 Section 5.1, reserved (local).

A PRIORITY or WINDOW_UPDATE frame MAY be received in this state.
Receiving any type of frame other than RST_STREAM, PRIORITY, or
WINDOW_UPDATE on a stream in this state MUST be treated as a
connection error (Section 5.4.1) of type PROTOCOL_ERROR.

Evidence: RFC 9113 Section 5.1.

DATA is not one of the permitted frame types for reserved (local), so DATA on that state must become a connection-level PROTOCOL_ERROR. The same reserved-state rule exists in the opposite direction for reserved (remote): frames outside that state's receive-side allowed set must also become connection-level PROTOCOL_ERROR.

Relevant Source Code

codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java:361-385

Http2Exception error = null;
switch (stream.state()) {
    case OPEN:
    case HALF_CLOSED_LOCAL:
        break;
    case HALF_CLOSED_REMOTE:
    case CLOSED:
        error = streamError(stream.id(), STREAM_CLOSED, "Stream %d in unexpected state: %s",
            stream.id(), stream.state());
        break;
    default:
        error = streamError(stream.id(), PROTOCOL_ERROR,
            "Stream %d in unexpected state: %s", stream.id(), stream.state());
        break;
}
...
flowController.receiveFlowControlledFrame(stream, data, padding, endOfStream);
...
if (error != null) {
    throw error;
}

For RESERVED_LOCAL, the default branch creates streamError(..., PROTOCOL_ERROR) rather than connectionError(PROTOCOL_ERROR). Flow-control processing runs before the prepared error is thrown.

codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2LocalFlowController.java:273-278

if (stream != null && !isClosed(stream)) {
    // Apply the stream-level flow control
    FlowState state = state(stream);
    state.endOfStream(endOfStream);
    state.receiveFlowControlledFrame(dataLength);
}

codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2LocalFlowController.java:540-552

public void receiveFlowControlledFrame(int dataLength) throws Http2Exception {
    throw new UnsupportedOperationException();
}
...
public void endOfStream(boolean endOfStream) {
    throw new UnsupportedOperationException();
}

In the default flow-controller path for a reserved stream, DATA can throw UnsupportedOperationException before the decoder throws its prepared streamError.

codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionHandler.java:691-701

Http2Exception embedded = getEmbeddedHttp2Exception(cause);
if (isStreamError(embedded)) {
    onStreamError(ctx, outbound, cause, (StreamException) embedded);
} else if (embedded instanceof CompositeStreamException) {
    ...
} else {
    onConnectionError(ctx, outbound, cause, embedded);
}

codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionHandler.java:725-729

if (http2Ex == null) {
    http2Ex = new Http2Exception(INTERNAL_ERROR, cause.getMessage(), cause);
}

A StreamException is handled as a stream error. A non-HTTP/2 exception is converted to connection INTERNAL_ERROR, not connection PROTOCOL_ERROR.

Implementation Behavior

When DATA is delivered on a RESERVED_LOCAL stream, Netty has two non-conforming behaviors:

  • With the default flow controller, the event throws UnsupportedOperationException.
  • If flow control is isolated, the decoder throws Http2Exception.StreamException with PROTOCOL_ERROR.

Neither behavior is the required connection-level PROTOCOL_ERROR. The same root cause affects RESERVED_REMOTE receive handling: reserved-state legality is not checked early and uniformly before listener or flow-control handling, so forbidden inbound frames can be accepted or reported with the wrong HTTP/2 error scope.

Inconsistency Reason

The standard requires connection error PROTOCOL_ERROR for forbidden inbound frames on reserved streams. Netty's default runtime path does not create an HTTP/2 PROTOCOL_ERROR at all for some cases, accepts others, and the decoder fallback can use stream-level PROTOCOL_ERROR. The error scope and, in the default path, the error code differ from RFC 9113.

Runtime Evidence

The probe created a server connection, remote parent stream 3 in HALF_CLOSED_REMOTE, and locally reserved push stream 2. It invoked the decoder's captured onDataRead callback for stream 2 with an empty DATA payload. With its default-flow setup, the proxy-based harness encountered UnsupportedOperationException; with a no-op flow controller isolating the state check, it observed stream-level PROTOCOL_ERROR. The first exception is a harness limitation, while the isolated callback result identifies the error scope used by the state check. Neither run is an end-to-end wire test.

Probe: ReservedLocalDataProbe.

The standalone Java probe was compiled against the checked Netty build and its local dependencies, then executed. The setup, inputs, and observed results are described in this section.

The control setup creates a valid pushed stream in RESERVED_LOCAL. Sending DATA to that stream does not produce connection PROTOCOL_ERROR.

Impact

Peers that send forbidden frames on reserved streams are not handled with the required HTTP/2 connection error. This can lead to incorrect error signaling and connection handling.

Fix Direction

For DATA on RESERVED_LOCAL and other reserved-state forbidden inbound frames, raise connectionError(PROTOCOL_ERROR, ...) before flow-control processing, listener delivery, and any stream-level error path. The check should cover both RESERVED_LOCAL and RESERVED_REMOTE with their respective receive-side allowed frame sets.

Dominant language
Java
Stars
35.1k
Forks
16.4k
Avg merge
1d 1h
Merged PRs (30d)
385

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from netty/netty

All issues in netty/netty

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.