{"record":{"id":"9061a1c135078d8d","repo":"golang/go","slug":"tls-unexpected-server-name-extension-in-server-he","errorCode":null,"errorMessage":"tls: unexpected server_name extension in server hello","messagePattern":"tls: unexpected server_name extension in server hello","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/tls/handshake_client_tls13.go","lineNumber":113,"sourceCode":"\t\tif err != nil {\n\t\t\tc.sendAlert(alertInternalError)\n\t\t\treturn err\n\t\t}\n\t\tacceptConfirmation := tls13.ExpandLabel(h, prk, \"ech accept confirmation\", confTranscript.Sum(nil), 8)\n\t\tif subtle.ConstantTimeCompare(acceptConfirmation, hs.serverHello.random[len(hs.serverHello.random)-8:]) == 1 {\n\t\t\ths.hello = hs.echContext.innerHello\n\t\t\tc.serverName = c.config.ServerName\n\t\t\ths.transcript = hs.echContext.innerTranscript\n\t\t\tc.echAccepted = true\n\n\t\t\tif hs.serverHello.encryptedClientHello != nil {\n\t\t\t\tc.sendAlert(alertUnsupportedExtension)\n\t\t\t\treturn errors.New(\"tls: unexpected encrypted client hello extension in server hello despite ECH being accepted\")\n\t\t\t}\n\n\t\t\tif hs.hello.serverName == \"\" && hs.serverHello.serverNameAck {\n\t\t\t\tc.sendAlert(alertUnsupportedExtension)\n\t\t\t\treturn errors.New(\"tls: unexpected server_name extension in server hello\")\n\t\t\t}\n\t\t} else {\n\t\t\ths.echContext.echRejected = true\n\t\t}\n\t}\n\n\tif err := transcriptMsg(hs.serverHello, hs.transcript); err != nil {\n\t\treturn err\n\t}\n\n\tc.buffering = true\n\tif err := hs.processServerHello(); err != nil {\n\t\treturn err\n\t}\n\tif err := hs.sendDummyChangeCipherSpec(); err != nil {\n\t\treturn err\n\t}\n\tif err := hs.establishHandshakeKeys(); err != nil {","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/tls/handshake_client_tls13.go#L95-L131","documentation":"Thrown during TLS 1.3 ECH processing when ECH was accepted but the inner ClientHello had no server_name (SNI), yet the server's ServerHello includes a server_name acknowledgment. This is contradictory: if the inner hello didn't advertise a name, the server must not acknowledge one.","triggerScenarios":"Triggered when hs.hello.serverName is empty (the inner hello has no SNI) AND hs.serverHello.serverNameAck is true after ECH acceptance is confirmed. The client sends alertUnsupportedExtension.","commonSituations":"ECH inner hello configured without a ServerName because config.ServerName was left empty. Mismatch between the inner ClientHello's SNI and the server's response. Server bug in ECH server_name acknowledgment logic.","solutions":["Set config.ServerName to the real backend hostname when using ECH — the inner hello needs a valid SNI.","Verify EncryptedClientHelloConfigList entries have correct DNS names matching config.ServerName.","If ECH is not needed, remove config.EncryptedClientHelloConfigList to disable ECH.","Ensure the ECH inner SNI and outer SNI are configured consistently."],"exampleFix":"// before — ECH without inner SNI\nconfig := &tls.Config{\n    EncryptedClientHelloConfigList: echList,\n    // ServerName missing!\n}\n\n// after — set the real hostname for the inner hello\nconfig := &tls.Config{\n    ServerName:                      \"backend.example.com\",\n    EncryptedClientHelloConfigList: echList,\n}","handlingStrategy":"validation","validationCode":"// Validate ECH config has a ServerName for the inner hello\nfunc validateECHConfig(config *tls.Config) error {\n    if config.EncryptedClientHelloConfigList != nil && config.ServerName == \"\" {\n        return fmt.Errorf(\"ServerName must be set when using ECH — the inner hello needs an SNI\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"conn, err := tls.Dial(\"tcp\", addr, config)\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected server_name extension in server hello\") {\n        // Set ServerName for the inner hello and retry\n        config.ServerName = hostname\n        conn, err = tls.Dial(\"tcp\", addr, config)\n    }\n}","preventionTips":["Always set config.ServerName when using ECH.","Validate ECH configuration before establishing connections.","Test ECH inner hello SNI with DNS tools that resolve HTTPS/SVCB records."],"tags":["tls","go","ech","tls13","sni","privacy"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}