Project

General

Profile

Actions

Security #9167

closed
JI SB

tls: evasion on fragmented handshake header across records

Security #9167: tls: evasion on fragmented handshake header across records

Added by Jason Ish about 2 months ago. Updated 7 days ago.

Status:
Closed
Priority:
Normal
Target version:
Affected Versions:
Label:
CVE:
Git IDs:

bea218e7b1dd8ffb09f250e62c096c6b3da749b4

Severity:
LOW
Disclosure Date:
12/27/2026

Description

Splitting the TLS handshake header across records disables all TLS inspection for the connection

TLDR

The vulnerability is that Suricata's TLS parser in src/app-layer-ssl.c treats a Handshake record that is too small to hold the whole 4-byte handshake header as a fatal error instead of waiting for the rest. When a client puts the first 1-3 bytes of its ClientHello in one small TLS record and the rest in later records, the parser returns a hard error, and Suricata reacts by turning off all application-layer parsing for that TCP flow in both directions. Because splitting a handshake message across record boundaries is explicitly allowed by the TLS specification and is accepted by normal TLS servers, an attacker who controls one end of a connection can complete a perfectly normal TLS session while Suricata extracts nothing from it. Every tls. rule (tls.sni, ja3/ja4, tls.cert_, tls.version, etc.) is silently bypassed for the connection; only a single generic anomaly event is raised. The root cause is on line 2601 (and its sibling on line 1779) of src/app-layer-ssl.c.

Root cause analysis

When Suricata has a complete TLS record whose content type is Handshake, it refuses to process it if the record body is shorter than a 4-byte handshake header, and returns a decoder error:

https://github.com/OISF/suricata/blob/bc48b4f44c7d3bdd06bf670405a2f016bb1157a1/src/app-layer-ssl.c#L2601-L2606

if (ssl_state->curr_connp->record_length < 4) {
    SSLParserReset(ssl_state);
    SSLSetEvent(ssl_state, TLS_DECODER_EVENT_INVALID_SSL_RECORD);
    SCLogDebug("record len < 4 => %u", ssl_state->curr_connp->record_length);
    return SSL_DECODER_ERROR(-1);
}

The problem is that a Handshake record carrying only 1-3 bytes is not invalid. In TLS the handshake is a byte stream that may be fragmented into records at any boundary (RFC 5246 §6.2.1, RFC 8446 §5.1), so the 4-byte handshake header itself may be split across two records. A compliant server simply buffers the first bytes and waits for the rest. Suricata instead treats "this one record does not yet contain a full header" as "this traffic is malformed" and aborts.

The parser already knows how to buffer a fragmented handshake message body across records: once the 4 header bytes have been read, if the announced message length exceeds the current record it allocates hs_buffer and resumes on the next record (https://github.com/OISF/suricata/blob/bc48b4f44c7d3bdd06bf670405a2f016bb1157a1/src/app-layer-ssl.c#L1815). But that logic only begins after the 4-byte header has been read, so a header that is itself split across records is never reassembled. The same gap produces a sibling hard error when a record ends 1-3 bytes into the next message's header, at https://github.com/OISF/suricata/blob/bc48b4f44c7d3bdd06bf670405a2f016bb1157a1/src/app-layer-ssl.c#L1779-L1782.

A single SSL_DECODER_ERROR(-1) does not just drop one record; it disables TLS inspection for the whole flow. The dataflow from the small record to that outcome is:

  1. The attacker's client sends a Handshake record whose body is the first 2 bytes of the ClientHello, e.g. the 7 bytes 16 03 01 00 02 01 00, then sends the remaining handshake bytes in later records.
  2. Protocol detection matches the |16 03 01| pattern and hands the flow to the TLS parser (SSLRegisterPatternsForProtocolDetection, https://github.com/OISF/suricata/blob/bc48b4f44c7d3bdd06bf670405a2f016bb1157a1/src/app-layer-ssl.c#L3050-L3052).
  3. SSLv3Decode (https://github.com/OISF/suricata/blob/bc48b4f44c7d3bdd06bf670405a2f016bb1157a1/src/app-layer-ssl.c#L2397) parses the 5-byte record header, sees a complete record of length 2, so the "record body incomplete" buffering does not apply, and it enters the Handshake branch.
  4. The record_length < 4 check (https://github.com/OISF/suricata/blob/bc48b4f44c7d3bdd06bf670405a2f016bb1157a1/src/app-layer-ssl.c#L2601) fires and returns SSL_DECODER_ERROR(-1).
  5. SSLDecode converts that into APP_LAYER_ERROR (https://github.com/OISF/suricata/blob/bc48b4f44c7d3bdd06bf670405a2f016bb1157a1/src/app-layer-ssl.c#L2780).
  6. AppLayerParserParse sees the negative status and jumps to its error handler (https://github.com/OISF/suricata/blob/bc48b4f44c7d3bdd06bf670405a2f016bb1157a1/src/app-layer-parser.c#L1652).
  7. The error handler calls StreamTcpDisableAppLayer(f) (https://github.com/OISF/suricata/blob/bc48b4f44c7d3bdd06bf670405a2f016bb1157a1/src/app-layer-parser.c#L1754), which marks app-layer detection complete and stops reassembly for both directions of the flow (https://github.com/OISF/suricata/blob/bc48b4f44c7d3bdd06bf670405a2f016bb1157a1/src/stream-tcp-reassemble.c#L445-L458).
  8. From then on Suricata parses no more TLS for the connection, so the real ClientHello/ServerHello/certificate that follow are never inspected, even though the bytes are present in the stream.

I confirmed this against a build of the parser at commit bc48b4f4. Feeding an intact ClientHello (SNI example.attacker.test) makes a tls.sni rule match. Feeding the identical ClientHello with its handshake header split so the first record is the 7 bytes 16 03 01 00 02 01 00 makes the tls.sni match disappear; only a raw TCP content rule (matching the same bytes still sitting in the stream) still fires, alongside the single TLS_DECODER_EVENT_INVALID_SSL_RECORD anomaly. Sending a fully valid ClientHello in a later record on the same flow also produces no match, confirming that the one small record disables TLS parsing for the entire flow rather than skipping a single record.

Suggested fix

Do not treat a short handshake record as fatal. Extend the existing hs_buffer reassembly so it also buffers a partial (1-3 byte) handshake header across record boundaries, the same way it already buffers a partial message body. Concretely, at the record_length < 4 site (line 2601) and at the residual-bytes site (line 1779), instead of raising TLS_DECODER_EVENT_INVALID_SSL_RECORD and returning SSL_DECODER_ERROR(-1), stash the available header bytes in a small buffer and return the "incomplete / need more data" result so the parser resumes when the next record arrives; only once at least 4 header bytes have been accumulated should the message length be read and the existing body-buffering path take over. This keeps genuinely malformed traffic detectable (for example via a length sanity cap) while no longer aborting on RFC-compliant fragmentation.

Reproducing with suricata-verify

Attached is the suricata-verify test tls-fragmented-handshake-header, a directory containing test.yaml, test.rules and input.pcap. Its flow carries the SNI example.attacker.test with the ClientHello's handshake header split so the first Handshake record is the 7 bytes 16 03 01 00 02 01 00. The test contains two rules: sid:1 matches on tls.sni (does the parser extract the SNI?) and sid:2 matches the same bytes as raw TCP content (a built-in control confirming the bytes reached the flow regardless of the TLS parser).

To run it against a build of Suricata:

  1. Build Suricata as usual; the test runs against ./src/suricata in your source tree.
  2. Get suricata-verify: git clone https://github.com/OISF/suricata-verify
  3. Unpack the attached artifacts into suricata-verify's tests/ directory, so that suricata-verify/tests/tls-fragmented-handshake-header/test.yaml exists.
  4. From the Suricata source/build directory, run the test by name:
cd /path/to/suricata
python3 /path/to/suricata-verify/run.py tls-fragmented-handshake-header

On current code the test reports FAILED: the raw-bytes control sub-check (sid:2) passes, but the tls.sni sub-check (sid:1) gets 0 matches and one INVALID_SSL_RECORD anomaly is raised. That failure is the evasion: the SNI bytes reached the flow but the TLS parser extracted nothing. Once the parser buffers partial handshake headers across records, the test passes, so it also serves as the regression test.

If Suricata aborts at startup with "failed to setup/expand stream session pool. Expand stream.memcap?", that is an environment limit on hosts with a very high CPU count (many worker threads), not a test failure; add --runmode single to the args: list in test.yaml, or raise stream.memcap, and re-run.

Credit

Please attribute Anthropic and Ada Logics (Adam Korczynski). This issue was found by Anthropic by using agents to study security of open source projects; Ada Logics validated the finding, created the report and communicated it.


Files

test.rules (274 Bytes) test.rules Jason Ish, 10/06/2026 02:12 AM
test.yaml (1.05 KB) test.yaml Jason Ish, 10/06/2026 02:12 AM
input.pcap (811 Bytes) input.pcap Jason Ish, 10/06/2026 02:12 AM

Subtasks 1 (0 open — 1 closed)

Security #9231: tls: evasion on fragmented handshake header across records (8.0.x backport)ClosedShivani BhardwajActions

SB Updated by Shivani Bhardwaj about 2 months ago Actions #1

  • Status changed from New to Assigned
  • Assignee changed from OISF Dev to Shivani Bhardwaj
  • Target version changed from TBD to 9.0.0-beta1

PA Updated by Philippe Antoine about 2 months ago Actions #2

I wonder if we should handle this as SECURITY since we emit the event TLS_DECODER_EVENT_INVALID_SSL_RECORD

PA Updated by Philippe Antoine about 2 months ago Actions #3

  • Severity set to LOW

I propose LOW severity as evasion with an important scope, but we emit an event (and thus drop in IPS mode)

SB Updated by Shivani Bhardwaj about 2 months ago Actions #4

  • Status changed from Assigned to In Review

SB Updated by Shivani Bhardwaj about 1 month ago Actions #5

  • Label Needs backport to 8.0 added

OT Updated by OISF Ticketbot about 1 month ago Actions #6

  • Subtask #9231 added

OT Updated by OISF Ticketbot about 1 month ago Actions #7

  • Label deleted (Needs backport to 8.0)

SB Updated by Shivani Bhardwaj about 1 month ago Actions #8

  • Subject changed from tls: fragmented handshake header across records disables TLS inspection to tls: evasion on fragmented handshake header across records

JI Updated by Jason Ish about 1 month ago Actions #9

  • GHSA set to GHSA-52mr-5g7v-6v3j

SB Updated by Shivani Bhardwaj about 1 month ago Actions #10

  • Status changed from In Review to Resolved

SB Updated by Shivani Bhardwaj about 1 month ago Actions #11

  • Status changed from Resolved to Closed

JI Updated by Jason Ish 25 days ago Actions #12

  • Git IDs updated (diff)

JI Updated by Jason Ish 7 days ago Actions #13

  • Private changed from Yes to No
Actions

Also available in: PDF Atom