XTLS/Xray-core · error
Invalid hex string
Error message
Invalid hex string
What it means
Thrown by ParseNoise when a noise entry of type "hex" has a packet value that is not valid hexadecimal. The raw string is passed straight to hex.DecodeString and any error (odd length, non-hex characters) is wrapped with this message. Decoding happens at config build time, before any traffic flows.
Source
Thrown at infra/conf/freedom.go:221
min, max, err := ParseRangeString(noise.Packet)
if err != nil {
return nil, errors.New("invalid value for rand Length").Base(err)
}
NConfig.LengthMin = uint64(min)
NConfig.LengthMax = uint64(max)
if NConfig.LengthMin == 0 {
return nil, errors.New("rand lengthMin or lengthMax cannot be 0")
}
case "str":
// user input string
NConfig.Packet = []byte(noise.Packet)
case "hex":
// user input hex
NConfig.Packet, err = hex.DecodeString(noise.Packet)
if err != nil {
return nil, errors.New("Invalid hex string").Base(err)
}
case "base64":
// user input base64
NConfig.Packet, err = base64.RawURLEncoding.DecodeString(strings.NewReplacer("+", "-", "/", "_", "=", "").Replace(noise.Packet))
if err != nil {
return nil, errors.New("Invalid base64 string").Base(err)
}
default:
return nil, errors.New("Invalid packet, only rand/str/hex/base64 are supported")
}
if noise.Delay != nil {
NConfig.DelayMin = uint64(noise.Delay.From)
NConfig.DelayMax = uint64(noise.Delay.To)
}
switch strings.ToLower(noise.ApplyTo) {View on GitHub (pinned to 7d214f8b09)
Solutions
- Provide an even-length hex string without prefix or separators, e.g. "deadbeef".
- Strip "0x" prefixes and whitespace before embedding.
- If the payload is not hex, switch the type to "base64" or "str".
Example fix
// before
{"type": "hex", "packet": "0xdeadbeef"}
// after
{"type": "hex", "packet": "deadbeef"} Defensive patterns
Strategy: validation
Validate before calling
if noise.Type == "hex" {
if _, err := hex.DecodeString(noise.Packet); err != nil {
return fmt.Errorf("noise packet is not valid hex (even length, no 0x prefix): %w", err)
}
} Prevention
- Use even-length hex without 0x prefix or whitespace.
- Generate hex with a library (xxd -p, hex.EncodeToString), never by hand.
When it happens
Trigger: {"type": "hex", "packet": "zz"} or "abc" (odd number of digits) or a string with 0x prefix. hex.DecodeString fails and the error is chained.
Common situations: Forgetting that Go hex requires even-length strings; including a "0x" prefix; pasting base64 into a hex field; whitespace mixed in.
Related errors
- invalid value for rand Length
- Invalid base64 string
- unsupported domain strategy: {}
- Invalid PacketsFrom
- invalid redirect address: {}
AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15).
Data as JSON: /api/errors/a2cb85c2f1846fc7.
Report an issue: GitHub.