balderdashy / sails

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

cors origin issue in sails js. #6887

Open Narendra93 opened 4 years ago

Narendra93 commented 4 years ago

Node version: v8.10.0 Sails version (sails): ^1.2.2 ORM hook version (sails-hook-orm): 2.1.1 Sockets hook version (sails-hook-sockets): ^2.0.0 Organics hook version (sails-hook-organics): ^0.16.0 Grunt hook version (sails-hook-grunt): Uploads hook version (sails-hook-uploads): DB adapter & version (e.g. sails-mongodb@5.55.5): ^1.0.1 Skipper adapter & version (e.g. skipper-s3@5.55.5):


in security.js configured. cors: { allRoutes: true, allowOrigins: ['*'], allowCredentials: false, allowRequestHeaders:'content-type,x-csrf-token,Authorization,token,Accept-Language' },

sailsbot commented 4 years ago

@Narendra93 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.

steinathan commented 4 years ago

What error are you seeing? this is not likely to be an issue

johnabrams7 commented 4 years ago

@Narendra93 - Thanks for bringing this us. To better understand this issue, can you provide us more info about the error and what you're seeing?

fabdrol commented 4 years ago

@johnabrams7 I'm seeing a similar problem with Sails 1.2.3 on Node 8.16.2. Here's what's happening:

I have a global CORS setup like thus, in accordance with the documentation:

/**
 * Security config
 */

module.exports.security = {
  cors: {
    allRoutes: true,
    allowOrigins: '*',
    allowCredentials: false,
    allowRequestHeaders: 'content-type,accept,authorization',
    allowRequestMethods: 'GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD',
    allowAnyOriginWithCredentialsUnsafe: true
  }
}

Once I request an unsecured endpoint (https://api.smartrecycling.org.uk/api/v1/cabin - as in, I can access it in a browser) using Axios in my app, a few things happen:

I then continued to try a "raw" OPTIONS request using Paw (a HTTP client like Postman):

Request:

OPTIONS /api/v1/cabin HTTP/1.1
Origin: http://localhost:3000
Access-Control-Request-Method: GET
Access-Control-Request-Headers: Content-Type, Authorization
Host: api.smartrecycling.org.uk
Connection: close
User-Agent: Paw/3.1.9 (Macintosh; OS X/10.15.1) GCDHTTPRequest

Response:

HTTP/1.1 200 OK
Server: nginx/1.10.3 (Ubuntu)
Date: Wed, 27 Nov 2019 10:21:42 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 13
Connection: close
X-Powered-By: Sails <sailsjs.com>
Allow: GET,HEAD,POST
ETag: W/"d-bMedpZYGrVt1nR4x+qdNZ2GqyRo"
Strict-Transport-Security: max-age=63072000; includeSubdomains

GET,HEAD,POST

Now, that response does not look right to me, considering the configuration above. Bug?

fabdrol commented 4 years ago

In addition: when accessing the same endpoint using websockets, it just works.

johnabrams7 commented 4 years ago

@fabdrol Thanks for the detailed exploration of this. I'll bring this up with the team for further examination. @Narendra93 What are your thoughts on the issue above?

fabdrol commented 4 years ago

Thanks @johnabrams7, let me know how I can help.

johnabrams7 commented 4 years ago

@fabdrol @Narendra93 Have you also tried setting allowCredentials: true, to allow browser cookies to be shared in CORS requests? Curious to see how that's also affecting allowAnyOriginWithCredentialsUnsafe: true for multiple systems being that it's particularly designed to work alongside having allowOrigins: '*' and allowCredentials: true at the same time.

fabdrol commented 4 years ago

@johnabrams7 I did try that, but that didn't seem to work. I'll give it another try just to be sure

johnabrams7 commented 4 years ago

@fabdrol Appreciate the help. Would you be willing to provide a minimal sails repo that reproduces this issue for the community?

fabdrol commented 4 years ago

@johnabrams7 Sorry, I completely didn't see this message. In any case, I have additional information, which may or may not be related: I have a different Sails installation where CORS works in nearly all cases - except when I try to do a file upload (using fetch API with mode set to cors)

eashaw commented 4 years ago

Hi @fabdrol, thanks for bringing this issue to our attention. What were your expecting to see for that particular response to the OPTIONS request?

praveenlv commented 3 years ago

what is the resolution for this issue

eashaw commented 3 years ago

what is the resolution for this issue

Hey @praveenlv, would you mind creating a new issue that explains what you're seeing with steps to reproduce in a new Sails app?