Azure + SignalR - Secure hubs to different connection types

Peter Lea

I have two hubs in a web role,

1) external facing hub meant to be consumed over https external endpoint for website users.

2) intended to be connected to over http on an internal endpoint by worker roles.

I would like the ability to secure access to the hubs somehow.

Is there anyway I can check to see what connection type the connecting user/worker role is using and accept/deny based on this?

Another method I thought of was perhaps using certificate authentication on the internal hubs but i'd rather not have to for speed etc.

GlobalHost.DependencyResolver.UseServiceBus(connectionString, "web");

// Web external connection
app.MapSignalR("/signalr", new HubConfiguration() 
     { EnableJavaScriptProxies = true, EnableDetailedErrors = false });

// Worker internal connection
app.MapSignalR("/signalr-internal", new HubConfiguration() 
     { EnableJavaScriptProxies = false, EnableDetailedErrors = true});    

EDIT: I've included my own answer

Peter Lea

I ended up probing the request environment variables and checking the servers localPort and request scheme in a custom AuthorizeAttribute. The only downside to this at the moment is that the javascript proxies will still generate the restricted hub info. But i'm working on that :).

I'll leave the question open for a bit to see if anyone can extend on this.

public class SignalrAuthorizeAttribute : Microsoft.AspNet.SignalR.AuthorizeAttribute, Microsoft.AspNet.SignalR.IDependencyResolver
{
    public override bool AuthorizeHubConnection(Microsoft.AspNet.SignalR.Hubs.HubDescriptor hubDescriptor, Microsoft.AspNet.SignalR.IRequest request)
    {
        bool isHttps = request.Environment["owin.RequestScheme"].ToString().Equals("https", StringComparison.OrdinalIgnoreCase) ? true : false;
        bool internalPort = request.Environment["server.LocalPort"].ToString().Equals("2000") ? true : false;

        switch(hubDescriptor.Name)
        {
            // External Hubs
            case "masterHub":
            case "childHub":
                if (isHttps && !internalPort) return base.AuthorizeHubConnection(hubDescriptor, request);
                break;
             // Internal hubs
            case "workerInHub":
            case "workerOutHub":
                if (!isHttps && internalPort) return base.AuthorizeHubConnection(hubDescriptor, request);
                break;
            default:
                break;
        }
        return false;
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Signalr create two connection to two different hubs

From Dev

Can SignalR group be shared between different hubs?

From Dev

Can SignalR group be shared between different hubs?

From Dev

SignalR hubs not registered when deployed to Azure

From Dev

SignalR hubs not registered when deployed to Azure

From Dev

signalR : /signalr/hubs is not generated

From Dev

SignalR - The signalr/hubs file

From Dev

SignalR: Error loading hubs

From Dev

ASP.Net SignalR: http://127.0.0.1/signalr/hubs (404 Not found) when accessed from different application

From Dev

Secure different types of unsecured applications by a reverse proxy

From Dev

Passing strongly typed Hubs in SignalR

From Dev

SignalR: Managing OnDisconnect() with multiple hubs

From Dev

SignalR Scaleout on Azure RedisCache - Connection issues

From Dev

SignalR 2 does not generate /signalr/hubs

From Dev

Connect to different Hubs on different pages

From Dev

SignalR connection

From Dev

signalr scale testing for broadcast messages using hubs

From Dev

SignalR with IoC (Castle Windsor) - which lifetime for hubs?

From Dev

minifying signalr hubs auto-generated proxy

From Dev

Injecting controller into SignalR Hubs using Simple Injector

From Dev

SignalR with IoC (Castle Windsor) - which lifetime for hubs?

From Dev

Creating multiple hubs dynamically using SignalR

From Dev

signalR/hubs doesn't show hub method

From Dev

How to establish secure connection string from on premises to SQL Azure Database

From Dev

SQL Azure Database. Login with non-secure connection string

From Dev

Secure connection string from winforms app to Azure SQL

From Dev

Xamarin SignalR - using the same connection proxy in a different Fragment/Activity

From Dev

SignalR 2.0 error /signalr/hubs 404 (Not Found) when using IIS

From Dev

azure notification hubs - app uninstall

Related Related

  1. 1

    Signalr create two connection to two different hubs

  2. 2

    Can SignalR group be shared between different hubs?

  3. 3

    Can SignalR group be shared between different hubs?

  4. 4

    SignalR hubs not registered when deployed to Azure

  5. 5

    SignalR hubs not registered when deployed to Azure

  6. 6

    signalR : /signalr/hubs is not generated

  7. 7

    SignalR - The signalr/hubs file

  8. 8

    SignalR: Error loading hubs

  9. 9

    ASP.Net SignalR: http://127.0.0.1/signalr/hubs (404 Not found) when accessed from different application

  10. 10

    Secure different types of unsecured applications by a reverse proxy

  11. 11

    Passing strongly typed Hubs in SignalR

  12. 12

    SignalR: Managing OnDisconnect() with multiple hubs

  13. 13

    SignalR Scaleout on Azure RedisCache - Connection issues

  14. 14

    SignalR 2 does not generate /signalr/hubs

  15. 15

    Connect to different Hubs on different pages

  16. 16

    SignalR connection

  17. 17

    signalr scale testing for broadcast messages using hubs

  18. 18

    SignalR with IoC (Castle Windsor) - which lifetime for hubs?

  19. 19

    minifying signalr hubs auto-generated proxy

  20. 20

    Injecting controller into SignalR Hubs using Simple Injector

  21. 21

    SignalR with IoC (Castle Windsor) - which lifetime for hubs?

  22. 22

    Creating multiple hubs dynamically using SignalR

  23. 23

    signalR/hubs doesn't show hub method

  24. 24

    How to establish secure connection string from on premises to SQL Azure Database

  25. 25

    SQL Azure Database. Login with non-secure connection string

  26. 26

    Secure connection string from winforms app to Azure SQL

  27. 27

    Xamarin SignalR - using the same connection proxy in a different Fragment/Activity

  28. 28

    SignalR 2.0 error /signalr/hubs 404 (Not Found) when using IIS

  29. 29

    azure notification hubs - app uninstall

HotTag

Archive