Coder Social home page Coder Social logo

Comments (15)

gyf19 avatar gyf19 commented on May 10, 2024

from signalr.

davidfowl avatar davidfowl commented on May 10, 2024

Are we still doing this for 0.4?

from signalr.

dsosunov avatar dsosunov commented on May 10, 2024

+1

from signalr.

dsosunov avatar dsosunov commented on May 10, 2024

+1

from signalr.

wpoch avatar wpoch commented on May 10, 2024

+1

from signalr.

yvbeek avatar yvbeek commented on May 10, 2024

+1

Don't really need JSONP solution.
<add name="Access-Control-Allow-Origin" solution in web.config is fine.

However the /signalr/hubs script should be more flexible, the url /signalr shouldn't be hardcoded

from signalr.

davidfowl avatar davidfowl commented on May 10, 2024

@Zyphrax you can change it via $.connection.hub.url there isn't a good default other than the relative path and that works for 90% of the cases

from signalr.

stevozilik avatar stevozilik commented on May 10, 2024

+1

from signalr.

davidemanske avatar davidemanske commented on May 10, 2024

+1

from signalr.

davidfowl avatar davidfowl commented on May 10, 2024

This was implemented as a contribution (Thanks @codeputty).

To make this work with Persistent connections:

var connection = $.connection('http://somecrossdomainurl/echo')

connection.start({ transport: 'longPolling', xdomain: true });

We may tweak the api (i.e try to autodetect so you don't need to specify longpolling) but this is the current implementation.

from signalr.

stevozilik avatar stevozilik commented on May 10, 2024

Thanks for this! Does this mean though that xdomain only works with long polling and no other transport protocol? If so, is it technically possible for it to work with other protocols?

from signalr.

davidfowl avatar davidfowl commented on May 10, 2024

This feature is specifically about long polling. Other protocols aren't supported. You can check out CORS for an alternative to jsonp longpolling:

http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing
http://stackoverflow.com/questions/9984534/signalr-cross-domain-connections

from signalr.

yvbeek avatar yvbeek commented on May 10, 2024

The CORS solution is working quite well. It becomes problematic when you have signalr on a subdomain, more than one subdomain using it and using cookies.

The specification says that you can specify multiple domains for Access-Control-Allow-Origin, but that doesn't seem to work when you have Access-Control-Allow-Credentials set to true (for cookie support).

My workaround is (in Global.asax.cs of my SignalR hubs MVC website):

/// <summary>
/// Raises when the application processes a request.
/// </summary>
protected void Application_BeginRequest(object sender, EventArgs e) {
    string origin = Request.Headers["Origin"];
    Uri uri;

    // Validate the Request origin
    if (Uri.TryCreate(origin, UriKind.Absolute, out uri) &&
        uri.Host.EndsWith(FormsAuthentication.CookieDomain)) {
        Response.AddHeader("Access-Control-Allow-Origin", uri.Scheme + "://" + uri.Authority);
        Response.AddHeader("Access-Control-Allow-Credentials", "true");
    }
}

Another nice resource for CORS:
http://enable-cors.org/

from signalr.

yvbeek avatar yvbeek commented on May 10, 2024

In AspNetHandler.cs I see that you've implemented it like this:

// https://developer.mozilla.org/En/HTTP_Access_Control
string origin = context.Request.Headers["Origin"];
if (!String.IsNullOrEmpty(origin))
{
        context.Response.AddHeader("Access-Control-Allow-Origin", origin);
        context.Response.AddHeader("Access-Control-Allow-Credentials", "true");
}

This seems quite insecure. Now all origins are allowed. If you have a look at my code above you see that I compare the origin against the cookie domain. Could you implement something similar?

EDIT - one extra thing to note:
It would be better to somehow overwrite the Access-Control-Allow-Origin, instead of using AddHeader. Now if you have the Access-Control-Allow-Origin defined in your web.config, you'll end up with both values being sent to the client. Which will fail in almost all browsers (I think only Firefox supports that).

from signalr.

davidfowl avatar davidfowl commented on May 10, 2024

Insecure? Websockets has the same behavior as this by default. Also any
other random non browser client can call your service so im not sure
what you're protecting.

Also socket.io does the same. We want the experience to be as similar
to websockets as possible. If you have valid security concerns or
concrete evidence that what we're doing is insecure then I'd love to
know.

Sent from my Windows Phone
From: Zyphrax
Sent: 7/25/2012 3:19 AM
To: David Fowler
Subject: Re: [SignalR] Add support for X-domain long-polling with JSONP
(#6)
In AspNetHandler.cs I see that you've implemented it like this:

// https://developer.mozilla.org/En/HTTP_Access_Control
string origin = context.Request.Headers["Origin"];
if (!String.IsNullOrEmpty(origin))
{
        context.Response.AddHeader("Access-Control-Allow-Origin", origin);
        context.Response.AddHeader("Access-Control-Allow-Credentials", "true");
}

This seems quite insecure. Now all origins are allowed. If you have a
look at my code above you see that I compare the origin against the
cookie domain. Could you implement something similar?


Reply to this email directly or view it on GitHub:
#6 (comment)

from signalr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.