{"record":{"id":"8c2ee7075b86cb85","repo":"Kareadita/Kavita","slug":"ip-address-invalid","errorCode":"ip-address-invalid","errorMessage":"ip-address-invalid","messagePattern":"ip-address-invalid","errorType":"exception","errorClass":"KavitaException","httpStatus":400,"severity":"error","filePath":"Kavita.Services/SettingsService.cs","lineNumber":350,"sourceCode":"                unitOfWork.SettingsRepository.Update(setting);\n            }\n\n            updateTask = updateTask || UpdateSchedulingSettings(setting, updateSettingsDto);\n\n            UpdateEmailSettings(setting, updateSettingsDto);\n            updatedOidcSettings = await UpdateOidcSettings(setting, updateSettingsDto) || updatedOidcSettings;\n\n\n            if (setting.Key == ServerSettingKey.IpAddresses && updateSettingsDto.IpAddresses != setting.Value)\n            {\n                if (OsInfo.IsDocker) continue;\n                // Validate IP addresses\n                foreach (var ipAddress in updateSettingsDto.IpAddresses.Split(',',\n                             StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries))\n                {\n                    if (!IPAddress.TryParse(ipAddress.Trim(), out _))\n                    {\n                        throw new KavitaException(\"ip-address-invalid\");\n                    }\n                }\n\n                setting.Value = updateSettingsDto.IpAddresses;\n                // IpAddresses is managed in appSetting.json\n                Configuration.IpAddresses = updateSettingsDto.IpAddresses;\n                unitOfWork.SettingsRepository.Update(setting);\n            }\n\n            if (setting.Key == ServerSettingKey.BaseUrl && updateSettingsDto.BaseUrl + string.Empty != setting.Value)\n            {\n                var path = !updateSettingsDto.BaseUrl.StartsWith('/')\n                    ? $\"/{updateSettingsDto.BaseUrl}\"\n                    : updateSettingsDto.BaseUrl;\n                path = !path.EndsWith('/')\n                    ? $\"{path}/\"\n                    : path;\n                setting.Value = path;","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/Kareadita/Kavita/blob/9c3e5400007f8a0282f7d883f2ad5e71716e514d/Kavita.Services/SettingsService.cs#L332-L368","documentation":"Thrown by SettingsService when updating ServerSettingKey.IpAddresses and one of the comma-separated values fails IPAddress.TryParse. Kavita binds the server to these addresses, so each must be a valid IPv4/IPv6 literal. Note: under Docker (OsInfo.IsDocker) the check is skipped because IP binding is managed by the container runtime.","triggerScenarios":"Saving server settings with an IpAddresses string like '127.0.0.1, notanip, ::1' where one token is not a parseable IP address; the loop parses each comma-separated entry and throws on the first invalid one.","commonSituations":"Typo in the IP field ('1.2.3'); entering a hostname instead of an IP ('localhost'); trailing junk after an address; or copying a CIDR notation ('10.0.0.0/24') which TryParse rejects.","solutions":["Enter only valid IPv4/IPv6 literals separated by commas, e.g. '127.0.0.1, ::1'.","Use 'localhost' only if you mean loopback - prefer '127.0.0.1' since the validator wants an IP literal.","Remove CIDR masks; Kavita binds addresses, not ranges.","If running in Docker, set bind addresses via the container/port config instead of this setting."],"exampleFix":"// before\nupdateSettingsDto.IpAddresses = \"127.0.0.1, localhost, ::1\";\nawait settingsService.UpdateSettings(updateSettingsDto);\n\n// after\nupdateSettingsDto.IpAddresses = \"127.0.0.1, ::1\";\nawait settingsService.UpdateSettings(updateSettingsDto);","handlingStrategy":"validation","validationCode":"var ips = updateSettingsDto.IpAddresses.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);\nif (ips.Any(ip => !IPAddress.TryParse(ip, out _)))\n    return BadRequest(\"ip-address-invalid\");\nawait settingsService.UpdateSettings(updateSettingsDto);","typeGuard":"static bool AllValidIps(string csv) => csv.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)\n    .All(ip => IPAddress.TryParse(ip, out _));","tryCatchPattern":null,"preventionTips":["Enter only IPv4/IPv6 literals separated by commas.","Avoid hostnames, CIDR notation, and trailing junk.","Under Docker, set bind addresses via container config, not this setting."],"tags":["settings","validation","network","configuration","server"],"backgroundTag":null,"analyzedSha":"9c3e5400007f8a0282f7d883f2ad5e71716e514d","analyzedAt":"2026-08-13T19:06:05.897Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}