-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get Socket.io working in SSR environment #198
Comments
This is practical in theory but not in practice. Grab a random developer and ask him to explain something as basic as click jacking or csrf to you - they can't. Asking them to make sure their app is secure is a hefty request. Wordpress suffered from a bunch of security issues for a long time, and it's a hard thing to recover from. You lose trust, and a large majority of sites/apps are not actively maintained and would remain vulnerable even after a patch is out. |
@DesignByOnyx I felt your words even as I typed the original phrase. :) |
Yeah - I'm sure. I don't know how to solve it. So let me get this straight - user-specific requests will be going across a single socket connection during SSR? If so, coming up with a solution might pave a way to make socket communication more secure even on clients. For example, instead of emitting "update" events, we emit instead |
@DesignByOnyx We tell people not to use done-serve in production for precisely these types of concerns (security the big one, and to some degree performance as well). Maintaining a production quality server is a huge project, and we want to make it clear that done-serve isn't such a project. That doesn't mean developers need to do it all themselves. They can use Express or Hapi or some other framework where the maintainers do put in the level of care that's needed. It's not DoneJS' mission to be full-stack, we provide SSR b/c that is necessary for good user experience. |
@matthewp What are we suggesting people use for server side rendering of their production donejs-apps then? |
done-ssr or done-ssr-middleware. You can use either with Express or Feathers or Hapi or anything else. done-serve, the cli, is the only thing that's not for production. |
Oh I misunderstood, again, thanks |
I think my Deploy donejs applications in production guide could address and solve that. as done ssr is production ready but it needs some Application Delivery Controller and on large deployments also a special dns layer as extra layer on top. This is current work in progressi try to port some of my success fullest Production Setups as easy use able examples |
@marshallswain @matthewp canjs/can-connect-feathers#104 |
This is an epic for keeping track of all the moving parts it takes to get Socket.io working in SSR.
It's in the early Proof of Concept / planning stage right now. After talking with @BigAB, @matthewp, and @daffl about the moving parts, it looks to me like this could very well be the best solution for implementing SSR in a Feathers-connected app. If it works out, setting up your client app would be a two step process:
steal-socket.io
instead ofsocket.io-client
.Everything else would be exactly the same as if you were creating the app without SSR.
Basic Idea
SSR for apps that use XHRs is quite simple because the connection isn't stateful. Currently, with feathers-socketio and feathers-authentication, the socket auth is stateful in order to identify which socket connections should receive server-side events. Since SSR won't need those, we can implement a stateless, shared socket for all connected clients.
Also important to note is that while it's possible to directly access the Feathers app if the SSR server and the Feathers server are on the same machine, I'm purposely ignoring that solution. I favor a setup that that will work when the API server and SSR server are separate, which will technically still work if they're on the same machine.
Why it's a good idea
Caveats
feathersClient.authenticate()
during the SSR loading process, or it will statefully authenticate the socket. A shared, authenticated socket could potentially return private data to the wrong user. While we could figure out a way to preventfeathersClient.authenticate()
from being called on the SSR server. the developer should take care of this. It just needs to be clearly documented.Making it work
Session.get()
instead ofSession.create()
!window.doneSsr
.steal-socket.io
can-zone plugin similar to the XHR zone plugin in Done-SSR thatsocket.emit
to approved domains so that the payload includes the JWT token on a special param.WS_CACHE
global to send in the initial page load HTML, similar to theXHR_CACHE
.WS_CACHE
. That's a better place for it than in can-connect-feathers or another can-connect behavior, since steal-socket.io's main purpose is to assist with SSR.config
property that points to a file containing the configuration with the extra zones. done-serve isn't "production ready", but this would make setting up the development environment much easier.For consideration once it's working
The text was updated successfully, but these errors were encountered: