{"record":{"id":"3316ad73b36bd0b6","repo":"XTLS/Xray-core","slug":"invalid-base64-string","errorCode":null,"errorMessage":"Invalid base64 string","messagePattern":"Invalid base64 string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"infra/conf/freedom.go","lineNumber":228,"sourceCode":"\t\t\treturn nil, errors.New(\"rand lengthMin or lengthMax cannot be 0\")\n\t\t}\n\n\tcase \"str\":\n\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:","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/infra/conf/freedom.go#L210-L246","documentation":"Thrown by ParseNoise when a noise entry of type \"base64\" cannot be decoded. Xray first translates URL-safe characters and strips '=' padding via a replacer, then uses RawURLEncoding; input that still fails (invalid characters, bad length) raises this error with the decode cause chained. Build-time only, like the other noise errors.","triggerScenarios":"{\"type\": \"base64\", \"packet\": \"aGVsbG8=\"} fails only if padding handling leaves an invalid length; in practice triggers on non-base64 characters or whitespace, e.g. \"hello world!!\" or truncated input. Mixed standard/URL-safe alphabets are tolerated by the replacer.","commonSituations":"Pasting text with spaces or newlines; truncated base64 from manual copying; assuming arbitrary strings are valid base64.","solutions":["Use clean base64 (standard or URL-safe; '=' padding is stripped automatically), e.g. \"aGVsbG8\".","Trim whitespace/newlines before embedding the value.","For raw ASCII payloads use type \"str\" instead of base64."],"exampleFix":"// before\n{\"type\": \"base64\", \"packet\": \"hello world!!\"}\n\n// after\n{\"type\": \"base64\", \"packet\": \"aGVsbG8=\"}","handlingStrategy":"validation","validationCode":"if noise.Type == \"base64\" {\n    s := strings.NewReplacer(\"+\", \"-\", \"/\", \"_\", \"=\", \"\").Replace(strings.TrimSpace(noise.Packet))\n    if _, err := base64.RawURLEncoding.DecodeString(s); err != nil {\n        return fmt.Errorf(\"noise packet is not valid base64: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trim whitespace/newlines from embedded base64 values.","Produce base64 with a tool/library, not manual editing.","Prefer type \"str\" for plain ASCII payloads."],"tags":["go","xray","freedom","noise","base64","config","validation"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}