{"record":{"id":"10b75ceb8318c7c0","repo":"golang/go","slug":"tls-server-sent-non-zero-legacy-tls-compression-m","errorCode":null,"errorMessage":"tls: server sent non-zero legacy TLS compression method","messagePattern":"tls: server sent non-zero legacy TLS compression method","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/tls/handshake_client_tls13.go","lineNumber":201,"sourceCode":"\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\n\n\treturn nil\n}\n\n// sendDummyChangeCipherSpec sends a ChangeCipherSpec record for compatibility","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/tls/handshake_client_tls13.go#L183-L219","documentation":"Thrown in checkServerHelloOrHRR() when the TLS 1.3 ServerHello has a non-zero compression_method field. TLS 1.3 removed compression entirely (it enabled CRIME/BREACH attacks) — the legacy compression_method field must be zero.","triggerScenarios":"Triggered when hs.serverHello.compressionMethod != compressionNone (0). The client sends alertDecodeError. The server selected a compression method, which is forbidden and a security concern.","commonSituations":"Server that doesn't properly implement TLS 1.3 and still tries to negotiate compression. Legacy server software with incomplete TLS 1.3 support. Security risk: TLS compression is the basis for CRIME and BREACH attacks.","solutions":["Server must set compression_method to 0 in all TLS 1.3 handshake messages.","This is both a protocol violation and a security risk — upgrade the server software immediately.","If the server cannot be upgraded, restrict client to TLS 1.2 (where compression is also disabled by default in Go).","Run a TLS scanner (e.g. testssl.sh) to identify other server compliance issues."],"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(), \"non-zero legacy TLS compression method\") {\n        // Security risk + protocol violation — fall back to TLS 1.2\n        config.MaxVersion = tls.VersionTLS12\n        conn, err = tls.Dial(\"tcp\", addr, config)\n    }\n}","preventionTips":["Immediately upgrade server software — TLS compression is a known security vulnerability (CRIME/BREACH).","Disable TLS compression on all servers regardless of version.","Scan servers with testssl.sh to detect compression support."],"tags":["tls","go","tls13","compression","protocol-violation","security"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}