balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.84k stars 1.95k forks source link

Sails not setting cookie on CORS login #5629

Open mihaa1 opened 5 years ago

mihaa1 commented 5 years ago

Node version: 10.15.0 Sails version (sails):1.1.0 ORM hook version (sails-hook-orm):2.1.1 Sockets hook version (sails-hook-sockets): 1.5.5 Organics hook version (sails-hook-organics): 0.15.0 Grunt hook version (sails-hook-grunt): 3.1.0 Uploads hook version (sails-hook-uploads):? DB adapter & version : sails-postgresql@1.0.2 Skipper adapter & version : skipper-disk@0.5.6


I have an angular SPA with a Sails backend. The angular app is served from a separate port than the sails app (sails is runnnig on 1337 and angular on 4200). I am trying to do a login request, and save the session cookie. This works if I host the client app on the same port, but if I make the request from 4200 the cookie isn't registered automatically.

Tried enabling CORS, with credentials. Also tried to "allowResponseHeaders" - and set the cookie manually but with no luck.

What am I missing? Is this something on the client side? Do i need to enable something else in the sails configuration?

sailsbot commented 5 years ago

@mihaa1 Thanks for posting! We'll take a look as soon as possible.

In the mean time, there are a few ways you can help speed things along:

Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.

For help with questions about Sails, click here.

raqem commented 5 years ago

Hi @mihaa1 I was looking into your issue but I need a little more info. Can you please provide your config/security.js to see how your CORS is set up? Here is the official docs on CORS if that is helpful.

mihaa1 commented 5 years ago

@raqem thanks for the response.

Here is my security.js file: cors: { allRoutes: true, allowOrigins: ['http://localhost:4200'], allowCredentials: true, }, csrf: true

crh3675 commented 5 years ago

Hmm, different port with cookie? Typically an SSL cookie (443) cannot be read by a port 80 request as the 443 is designated as secure. As per the RFC https://tools.ietf.org/html/rfc6265, the behavior you "want" to occur is considered insecure and I consider the Sails framework to be secure with its implementation. Meaning, you are breaking the "8.5" confidentiality clause of the RFC. I consider this to be an as-expected behavior - not a bug.

mihaa1 commented 5 years ago

@crh3675 so what I understand from you - is there is no way using the built in auth functionality in sails to authenticate a client which is hosted on another domain?

What do you suggest I do in this situation? Move to JWT perhaps?

crh3675 commented 5 years ago

What I typically do is use an