From 3fb356ddb6c6a7c01bf348caa4b696abd0531053 Mon Sep 17 00:00:00 2001 From: Leonardo Galli Date: Wed, 26 Jul 2017 23:24:28 +0200 Subject: [PATCH] Fixed: No API Key required with SignalR connections. --- .../NzbDronePersistentConnection.cs | 23 ++++++++++++++++++- src/UI/Shared/SignalRBroadcaster.js | 4 ++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.SignalR/NzbDronePersistentConnection.cs b/src/NzbDrone.SignalR/NzbDronePersistentConnection.cs index dfa063a0e..b3342ffba 100644 --- a/src/NzbDrone.SignalR/NzbDronePersistentConnection.cs +++ b/src/NzbDrone.SignalR/NzbDronePersistentConnection.cs @@ -1,5 +1,7 @@ -using Microsoft.AspNet.SignalR; +using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR.Infrastructure; +using NzbDrone.Common.Extensions; +using NzbDrone.Core.Configuration; namespace NzbDrone.SignalR { @@ -12,9 +14,28 @@ namespace NzbDrone.SignalR { private IPersistentConnectionContext Context => ((ConnectionManager)GlobalHost.ConnectionManager).GetConnection(GetType()); + private static string API_KEY; + + public NzbDronePersistentConnection(IConfigFileProvider configFileProvider) + { + API_KEY = configFileProvider.ApiKey; + } + public void BroadcastMessage(SignalRMessage message) { Context.Connection.Broadcast(message); } + + protected override bool AuthorizeRequest(IRequest request) + { + var apiKey = request.QueryString["apiKey"]; + + if (apiKey.IsNotNullOrWhiteSpace() && apiKey.Equals(API_KEY)) + { + return true; + } + + return false; + } } } \ No newline at end of file diff --git a/src/UI/Shared/SignalRBroadcaster.js b/src/UI/Shared/SignalRBroadcaster.js index 2d5292760..204f77ab5 100644 --- a/src/UI/Shared/SignalRBroadcaster.js +++ b/src/UI/Shared/SignalRBroadcaster.js @@ -26,7 +26,7 @@ module.exports = { var tryingToReconnect = false; var messengerId = 'signalR'; - this.signalRconnection = $.connection(StatusModel.get('urlBase') + '/signalr'); + this.signalRconnection = $.connection(StatusModel.get('urlBase') + '/signalr', { apiKey: window.NzbDrone.ApiKey }); this.signalRconnection.stateChanged(function(change) { console.debug('SignalR: [{0}]'.format(getStatus(change.newState))); @@ -73,4 +73,4 @@ module.exports = { return this; } -}; \ No newline at end of file +};