XTLS/Xray-core · error
invalid header
Error message
invalid header: %v
What it means
Record framing check in DecodeHeader: the 5-byte TLS-like header must start with bytes 23,3,3 and carry a length in 17..16640 (TLS 1.3 record limits). Violating either yields this error with the offending bytes dumped. Its exact text is a contract — client Read() matches on the 'invalid header: ' prefix to detect 0-RTT expiry (see the DO NOT CHANGE comment).
Solutions
- For clients: treat this as a trigger to renegotiate a new handshake
- For servers: log the peer address; malformed records usually mean protocol mismatch or probing
- Do not alter the message text; client 0-RTT detection depends on it
- Verify peers run compatible encryption versions
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at proxy/vless/encryption/common.go:218 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15).
Data as JSON: /api/errors/2bcc71e9d33d0766.
Report an issue: GitHub.
Appendix: source
Thrown at proxy/vless/encryption/common.go:218
func DecodeLength(b []byte) int {
return int(b[0])<<8 | int(b[1])
}
func EncodeHeader(h []byte, l int) {
h[0] = 23
h[1] = 3
h[2] = 3
h[3] = byte(l >> 8)
h[4] = byte(l)
}
func DecodeHeader(h []byte) (l int, err error) {
l = int(h[3])<<8 | int(h[4])
if h[0] != 23 || h[1] != 3 || h[2] != 3 {
l = 0
}
if l < 17 || l > 16640 { // TLS 1.3 max record: 16384 + 256 (RFC 8446 §5.2)
err = errors.New("invalid header: " + fmt.Sprintf("%v", h[:5])) // DO NOT CHANGE: relied by client's Read()
}
return
}
func ParsePadding(padding string, paddingLens, paddingGaps *[][3]int) (err error) {
if padding == "" {
return
}
maxLen := 0
for i, s := range strings.Split(padding, ".") {
x := strings.Split(s, "-")
if len(x) < 3 || x[0] == "" || x[1] == "" || x[2] == "" {
return errors.New("invalid padding lenth/gap parameter: " + s)
}
y := [3]int{}
if y[0], err = strconv.Atoi(x[0]); err != nil {
return
}View on GitHub (pinned to 7d214f8b09)