{"record":{"id":"1c9176a697dc4d02","repo":"golang/go","slug":"tls-server-did-not-echo-the-legacy-session-id","errorCode":null,"errorMessage":"tls: server did not echo the legacy session ID","messagePattern":"tls: server did not echo the legacy session ID","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/tls/handshake_client_tls13.go","lineNumber":196,"sourceCode":"\tif hs.serverHello.vers != VersionTLS12 {\n\t\tc.sendAlert(alertIllegalParameter)\n\t\treturn errors.New(\"tls: server sent an incorrect legacy version\")\n\t}\n\n\tif hs.serverHello.ocspStapling ||\n\t\ths.serverHello.ticketSupported ||\n\t\ths.serverHello.extendedMasterSecret ||\n\t\ths.serverHello.secureRenegotiationSupported ||\n\t\tlen(hs.serverHello.secureRenegotiation) != 0 ||\n\t\tlen(hs.serverHello.alpnProtocol) != 0 ||\n\t\tlen(hs.serverHello.scts) != 0 {\n\t\tc.sendAlert(alertUnsupportedExtension)\n\t\treturn errors.New(\"tls: server sent a ServerHello extension forbidden in TLS 1.3\")\n\t}\n\n\tif !bytes.Equal(hs.hello.sessionId, hs.serverHello.sessionId) {\n\t\tc.sendAlert(alertIllegalParameter)\n\t\treturn errors.New(\"tls: server did not echo the legacy session ID\")\n\t}\n\n\tif hs.serverHello.compressionMethod != compressionNone {\n\t\tc.sendAlert(alertDecodeError)\n\t\treturn errors.New(\"tls: server sent non-zero legacy TLS compression method\")\n\t}\n\n\tselectedSuite := mutualCipherSuiteTLS13(hs.hello.cipherSuites, hs.serverHello.cipherSuite)\n\tif hs.suite != nil && selectedSuite != hs.suite {\n\t\tc.sendAlert(alertIllegalParameter)\n\t\treturn errors.New(\"tls: server changed cipher suite after a HelloRetryRequest\")\n\t}\n\tif selectedSuite == nil {\n\t\tc.sendAlert(alertIllegalParameter)\n\t\treturn errors.New(\"tls: server chose an unconfigured cipher suite\")\n\t}\n\ths.suite = selectedSuite\n\tc.cipherSuite = hs.suite.id","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/tls/handshake_client_tls13.go#L178-L214","documentation":"Thrown in checkServerHelloOrHRR() when the server's TLS 1.3 ServerHello does not echo back the client's legacy session ID. RFC 8446 section 4.1.3 requires the server to echo the client's session ID for middlebox compatibility — a non-matching session ID is a protocol violation.","triggerScenarios":"Triggered when bytes.Equal(hs.hello.sessionId, hs.serverHello.sessionId) returns false. The client sent a non-empty legacy session ID but the server returned a different value or omitted it.","commonSituations":"Non-compliant server that generates a new session ID instead of echoing the client's. TLS middlebox or proxy modifying the session ID field. Server implementation that doesn't follow the middlebox compatibility requirement. Server that treats session ID differently in TLS 1.3.","solutions":["Server must echo the client's legacy session ID verbatim in the TLS 1.3 ServerHello per RFC 8446 section 4.1.3.","Check for middlebox or proxy interference modifying the session ID field.","If the server cannot be fixed, restrict the client to TLS 1.2.","Report as a server compliance issue with a packet capture showing the mismatched session IDs."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"conn, err := tls.Dial(\"tcp\", addr, config)\nif err != nil {\n    if strings.Contains(err.Error(), \"did not echo the legacy session ID\") {\n        // Server protocol violation — fall back to TLS 1.2\n        config.MaxVersion = tls.VersionTLS12\n        conn, err = tls.Dial(\"tcp\", addr, config)\n    }\n}","preventionTips":["Capture handshakes with Wireshark to verify session ID echoing.","Report session ID echo violations to server vendors.","Keep a TLS 1.2 fallback for servers with broken middlebox compatibility."],"tags":["tls","go","tls13","session-id","protocol-violation","rfc8446"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}