mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-05 21:37:10 -04:00
fixes #1851 - EmbyServer crashes if staticly assigned IP address changes
This commit is contained in:
parent
cc62faa1c2
commit
389487638e
@ -331,6 +331,46 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||
return url;
|
||||
}
|
||||
|
||||
private string NormalizeConfiguredLocalAddress(string address)
|
||||
{
|
||||
var index = address.Trim('/').IndexOf('/');
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
address = address.Substring(index + 1);
|
||||
}
|
||||
|
||||
return address.Trim('/');
|
||||
}
|
||||
|
||||
private bool ValidateHost(Uri url)
|
||||
{
|
||||
var hosts = _config
|
||||
.Configuration
|
||||
.LocalNetworkAddresses
|
||||
.Select(NormalizeConfiguredLocalAddress)
|
||||
.ToList();
|
||||
|
||||
if (hosts.Count == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var host = url.Host ?? string.Empty;
|
||||
|
||||
_logger.Debug("Validating host {0}", host);
|
||||
|
||||
if (_networkManager.IsInPrivateAddressSpace(host))
|
||||
{
|
||||
hosts.Add("localhost");
|
||||
hosts.Add("127.0.0.1");
|
||||
|
||||
return hosts.Any(i => host.IndexOf(i, StringComparison.OrdinalIgnoreCase) != -1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overridable method that can be used to implement a custom hnandler
|
||||
/// </summary>
|
||||
@ -350,6 +390,16 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||
return ;
|
||||
}
|
||||
|
||||
if (!ValidateHost(url))
|
||||
{
|
||||
httpRes.StatusCode = 400;
|
||||
httpRes.ContentType = "text/plain";
|
||||
httpRes.Write("Invalid host");
|
||||
|
||||
httpRes.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
var operationName = httpReq.OperationName;
|
||||
var localPath = url.LocalPath;
|
||||
|
||||
|
@ -821,42 +821,11 @@ namespace MediaBrowser.Server.Startup.Common
|
||||
|
||||
private string CertificatePath { get; set; }
|
||||
|
||||
private string NormalizeConfiguredLocalAddress(string address)
|
||||
{
|
||||
var index = address.Trim('/').IndexOf('/');
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
address = address.Substring(index + 1);
|
||||
}
|
||||
|
||||
return address.Trim('/');
|
||||
}
|
||||
private IEnumerable<string> GetUrlPrefixes()
|
||||
{
|
||||
var hosts = ServerConfigurationManager
|
||||
.Configuration
|
||||
.LocalNetworkAddresses
|
||||
.Select(NormalizeConfiguredLocalAddress)
|
||||
.ToList();
|
||||
var hosts = new List<string>();
|
||||
|
||||
if (hosts.Count == 0)
|
||||
{
|
||||
hosts.Add("+");
|
||||
}
|
||||
|
||||
if (!hosts.Contains("+", StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
if (!hosts.Contains("localhost", StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
hosts.Add("localhost");
|
||||
}
|
||||
|
||||
if (!hosts.Contains("127.0.0.1", StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
hosts.Add("127.0.0.1");
|
||||
}
|
||||
}
|
||||
hosts.Add("+");
|
||||
|
||||
return hosts.SelectMany(i =>
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user