Skip to content
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

CORS header Origin allowing any domain #217

Closed
bshamblen opened this issue Nov 3, 2016 · 8 comments
Closed

CORS header Origin allowing any domain #217

bshamblen opened this issue Nov 3, 2016 · 8 comments

Comments

@bshamblen
Copy link
Contributor

During a recent security scan of our production environment a potential CORS vulnerability was raised. It seems that sockjs automatically sets the Access-Control-Allow-Origin header to whatever the requesting domain is, if any sockjs path is referenced from another domain.

For example, if I request the URL https://www.meteor.com/sockjs/info from a jsfiddle script, the Access-Control-Allow-Origin value is set to https://fiddle.jshell.net, by sockjs.

screen shot 2016-11-03 at 3 26 15 pm

After looking at your source code, I noticed a hard coded reference where the requesting origin header is being used to set the response Access-Control-Allow-Origin header :

https://github.com/sockjs/sockjs-node/blob/master/src/trans-xhr.coffee#L63

For security purposes our application should not allow cross origin access to any paths. Would it be possible to add an option to disable this default behavior, or even the option to disable CORS completely, for the sockjs paths?

@brycekahle
Copy link
Contributor

I'd happily accept a PR that disables CORS completely or allows restricting the value.

@bshamblen
Copy link
Contributor Author

@brycekahle I'll have something for you to review early next week. Thanks.

@bshamblen
Copy link
Contributor Author

@brycekahle Do you know if the "origins": ["*:*"] key/value that's returned in the JSON response of the info endpoint is used by any sockjs clients, or is it purely for informational purposes? It would make sense to me to remove this key from the response if CORS were disabled, but I want to make sure it's not going to break anything downstream if I remove it. I searched the sockjs-client source code and didn't find any references to origins.

I don't see any integration tests, other than the sample test_server app. Is there some process you use to verify PRs, to check for errors? If not, I have a sample script that'll test my use case, which I can share when I submit the PR.

@brycekahle
Copy link
Contributor

Looks like it is ignored: https://github.com/sockjs/sockjs-protocol/blob/8816e93c695d92d6a16f744a6a8a08f22df64d7e/sockjs-protocol.py#L278

The tests are in the sockjs-protocol repo.

@bshamblen
Copy link
Contributor Author

@brycekahle I've run the tests in the sockjs-protocol repo against the changes I made in PR #218. All of the tests pass with the default configuration (in tests/test-server/config.js). If I add the disable_cors: true option to server_opts and retest, 8 tests fail, which is expected since many of the tests are checking for the existence of CORS headers.

@brycekahle
Copy link
Contributor

Fixed in #218

@fwhatley
Copy link

fwhatley commented Mar 10, 2023

I'd happily accept a PR that disables CORS completely or allows restricting the value.

Thanks for allowing us to disable CORS. It works beautifully.

Currently, we only have 2 options: enable CORS to all origins or disable it. I must enable CORS and limit it to a set of origins (URLs). Would you still happily accept a PR for this addition? I know the statement above was made 7 years ago hence asking. I'd be happy to make a PR to limit CORS to a set of origins.

@auvipy
Copy link
Contributor

auvipy commented Mar 11, 2023

I would like to know more about the implementation and implication of that approach, care to share more? or you can come with a draft proof of concept PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants