{"record":{"id":"69371a67f3d3dbde","repo":"XTLS/Xray-core","slug":"invalid-packet-only-rand-str-hex-base64-are-suppo","errorCode":null,"errorMessage":"Invalid packet, only rand/str/hex/base64 are supported","messagePattern":"Invalid packet, only rand/str/hex/base64 are supported","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"infra/conf/freedom.go","lineNumber":232,"sourceCode":"\t\t// user input string\n\t\tNConfig.Packet = []byte(noise.Packet)\n\n\tcase \"hex\":\n\t\t// user input hex\n\t\tNConfig.Packet, err = hex.DecodeString(noise.Packet)\n\t\tif err != nil {\n\t\t\treturn nil, errors.New(\"Invalid hex string\").Base(err)\n\t\t}\n\n\tcase \"base64\":\n\t\t// user input base64\n\t\tNConfig.Packet, err = base64.RawURLEncoding.DecodeString(strings.NewReplacer(\"+\", \"-\", \"/\", \"_\", \"=\", \"\").Replace(noise.Packet))\n\t\tif err != nil {\n\t\t\treturn nil, errors.New(\"Invalid base64 string\").Base(err)\n\t\t}\n\n\tdefault:\n\t\treturn nil, errors.New(\"Invalid packet, only rand/str/hex/base64 are supported\")\n\t}\n\n\tif noise.Delay != nil {\n\t\tNConfig.DelayMin = uint64(noise.Delay.From)\n\t\tNConfig.DelayMax = uint64(noise.Delay.To)\n\t}\n\tswitch strings.ToLower(noise.ApplyTo) {\n\tcase \"\", \"ip\", \"all\":\n\t\tNConfig.ApplyTo = \"ip\"\n\tcase \"ipv4\":\n\t\tNConfig.ApplyTo = \"ipv4\"\n\tcase \"ipv6\":\n\t\tNConfig.ApplyTo = \"ipv6\"\n\tdefault:\n\t\treturn nil, errors.New(\"Invalid applyTo, only ip/ipv4/ipv6 are supported\")\n\t}\n\treturn NConfig, nil\n}","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/infra/conf/freedom.go#L214-L250","documentation":"Thrown by FreedomClientConfig's noise packet builder when the noise.packet field's type prefix is not one of rand, str, hex, or base64. The noise feature prefixes user input with a type keyword (e.g. \"str:...\", \"hex:...\", \"rand:\") to decide how to decode the packet payload into raw bytes. Any unrecognized prefix falls into the default branch of the switch and fails immediately.","triggerScenarios":"Setting freedom.outboundSettings.noise.packet to a value whose prefix is anything except 'rand', 'str', 'hex', or 'base64' (case handling per switch), e.g. \"binary:0101\", \"bytes:AABB\", or a bare string with no recognized prefix keyword.","commonSituations":"Copying noise config examples from other projects (e.g. other proxy cores) that support different packet formats; typos like 'base63' or 'hexa'; upgrading configs where the noise feature changed accepted prefixes.","solutions":["Prefix the packet value with a supported type: use 'rand:' followed by a decimal length, 'str:' followed by plain text, 'hex:' followed by hex digits, or 'base64:' followed by base64 data","Check for typos in the prefix keyword and its trailing colon","Verify against the current Xray-core freedom noise documentation, since supported formats are fixed to rand/str/hex/base64"],"exampleFix":"// before\n\"noise\": { \"packet\": \"binary:01010101\" }\n// after\n\"noise\": { \"packet\": \"str:01010101\" }","handlingStrategy":"validation","validationCode":"// Go: validate noise packet before building config\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\nfunc validNoisePacket(p string) error {\n\tfor _, prefix := range []string{\"rand:\", \"str:\", \"hex:\", \"base64:\"} {\n\t\tif strings.HasPrefix(strings.ToLower(p), prefix) {\n\t\t\treturn nil\n\t\t}\n\t}\n\treturn fmt.Errorf(\"noise.packet must start with rand:/str:/hex:/base64:, got %q\", p)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate noise.packet prefix against rand/str/hex/base64 before emitting config","Add a JSON schema check for the noise object in CI config linting"],"tags":["xray","config","freedom","noise","validation"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}