diff options
| author | hatharry <hatharry@hotmail.com> | 2016-08-28 12:51:32 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-08-28 12:51:32 +0000 |
| commit | c974641a352685b2e6595dd7b291843c8e6364ac (patch) | |
| tree | 2e6ca83c4d08c5b676e12edae947e635d290bc3f /MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs | |
| parent | f21f9923de6291aaf985f32dbbbaddbb26d07fb1 (diff) | |
| parent | 81765ff29f624fd34e1abe3c7bb8149bbb001aef (diff) | |
Merge pull request #22 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs | 76 |
1 files changed, 72 insertions, 4 deletions
diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs index 17e4793cb..51a53fe21 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -67,6 +67,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer public override void Configure(Container container) { HostConfig.Instance.DefaultRedirectPath = DefaultRedirectPath; + HostConfig.Instance.LogUnobservedTaskExceptions = false; HostConfig.Instance.MapExceptionToStatusCode = new Dictionary<Type, int> { @@ -80,7 +81,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer {typeof (ApplicationException), 500} }; - HostConfig.Instance.DebugMode = true; + HostConfig.Instance.GlobalResponseHeaders = new Dictionary<string, string>(); + HostConfig.Instance.DebugMode = false; HostConfig.Instance.LogFactory = LogManager.LogFactory; @@ -250,7 +252,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer httpRes.Close(); } - catch (Exception errorEx) + catch { //_logger.ErrorException("Error this.ProcessRequest(context)(Exception while writing error to the response)", errorEx); } @@ -329,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> @@ -348,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; @@ -376,8 +428,24 @@ namespace MediaBrowser.Server.Implementations.HttpServer if (string.Equals(localPath, "/mediabrowser/", StringComparison.OrdinalIgnoreCase) || string.Equals(localPath, "/mediabrowser", StringComparison.OrdinalIgnoreCase) || - localPath.IndexOf("mediabrowser/web", StringComparison.OrdinalIgnoreCase) != -1 || - localPath.IndexOf("dashboard/", StringComparison.OrdinalIgnoreCase) != -1) + localPath.IndexOf("mediabrowser/web", StringComparison.OrdinalIgnoreCase) != -1) + { + httpRes.StatusCode = 200; + httpRes.ContentType = "text/html"; + var newUrl = urlString.Replace("mediabrowser", "emby", StringComparison.OrdinalIgnoreCase) + .Replace("/dashboard/", "/web/", StringComparison.OrdinalIgnoreCase); + + if (!string.Equals(newUrl, urlString, StringComparison.OrdinalIgnoreCase)) + { + httpRes.Write("<!doctype html><html><head><title>Emby</title></head><body>Please update your Emby bookmark to <a href=\"" + newUrl + "\">" + newUrl + "</a></body></html>"); + + httpRes.Close(); + return; + } + } + + if (localPath.IndexOf("dashboard/", StringComparison.OrdinalIgnoreCase) != -1 && + localPath.IndexOf("web/dashboard", StringComparison.OrdinalIgnoreCase) == -1) { httpRes.StatusCode = 200; httpRes.ContentType = "text/html"; |
