{"record":{"id":"8fb50d00c1970bc9","repo":"XTLS/Xray-core","slug":"unknown-type","errorCode":null,"errorMessage":"unknown type","messagePattern":"unknown type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"infra/conf/transport_finalmask.go","lineNumber":63,"sourceCode":"\t\tvar str string\n\t\tif err := json.Unmarshal(data, &str); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn []byte(str), nil\n\tcase \"hex\":\n\t\tvar str string\n\t\tif err := json.Unmarshal(data, &str); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn hex.DecodeString(str)\n\tcase \"base64\":\n\t\tvar str string\n\t\tif err := json.Unmarshal(data, &str); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn base64.StdEncoding.DecodeString(str)\n\tdefault:\n\t\treturn nil, errors.New(\"unknown type\")\n\t}\n}\n\nvar (\n\tcustomVarNamePattern = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`)\n\n\ttcpmaskLoader = NewJSONConfigLoader(ConfigCreatorCache{\n\t\t\"header-custom\": func() interface{} { return new(HeaderCustomTCP) },\n\t\t\"fragment\":      func() interface{} { return new(FragmentMask) },\n\t\t\"sudoku\":        func() interface{} { return new(Sudoku) },\n\t\t\"xmc\":           func() interface{} { return new(XMC) },\n\t}, \"type\", \"settings\")\n\n\tudpmaskLoader = NewJSONConfigLoader(ConfigCreatorCache{\n\t\t\"header-custom\": func() interface{} { return new(HeaderCustomUDP) },\n\t\t\"mkcp-legacy\":   func() interface{} { return new(MkcpLegacy) },\n\t\t\"noise\":         func() interface{} { return new(NoiseMask) },\n\t\t\"salamander\":    func() interface{} { return new(Salamander) },","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/infra/conf/transport_finalmask.go#L45-L81","documentation":"PraseByteSlice (infra/conf/transport_finalmask.go:63) decodes a raw JSON \"packet\" value according to the item's \"type\" field. Only \"\"/\"array\" (JSON byte array), \"str\", \"hex\", and \"base64\" are recognized; any other type string returns \"unknown type\" and the transport config fails to build.","triggerScenarios":"A TCPItem/UDPItem/NoiseItem with \"type\":\"utf8\" (or \"b64\", \"Hex\", any misspelling) and a non-empty packet. Note strings.ToLower is applied, so \"Hex\" works but \"hexadecimal\" does not. Empty type with a JSON array [104,105] is the default and valid.","commonSituations":"Hand-writing header-custom/noise masks and guessing the type vocabulary; copying examples from third-party clients that use different type names; typos like \"base64 \" with trailing whitespace.","solutions":["Set type to one of \"array\" (or omit), \"str\", \"hex\", \"base64\"","Match payload to type: str/hex/base64 take a JSON string; array takes [1,2,3]","Omit type entirely and supply the packet as a JSON byte array"],"exampleFix":"// before\n{ \"type\": \"ascii\", \"packet\": \"GET / HTTP/1.1\\r\\n\" }\n// after\n{ \"type\": \"str\", \"packet\": \"GET / HTTP/1.1\\r\\n\" }","handlingStrategy":"validation","validationCode":"const okTypes = new Set(['', 'array', 'str', 'hex', 'base64']);\nfor (const item of [...(mask.client??[]), ...(mask.server??[]), ...(mask.noise??[])]) {\n  if (item.packet && item.type && !okTypes.has(item.type.toLowerCase())) throw new Error(`unknown packet type: ${item.type}`);\n  if (['str','hex','base64'].includes((item.type??'').toLowerCase()) && typeof item.packet !== 'string') throw new Error('str/hex/base64 packets must be JSON strings');\n  if ((item.type??'') === '' || item.type === 'array') { if (!Array.isArray(item.packet)) throw new Error('array packets must be JSON byte arrays'); }\n}","typeGuard":"const isPacketType = (t: string) => ['','array','str','hex','base64'].includes(t.toLowerCase());","tryCatchPattern":null,"preventionTips":["Standardize on one encoding (hex or str) across all masks","Add a unit test that validates mask JSON against the allow-list before deploy"],"tags":["xray","go","transport","mask","json","config"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}