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 Support #141

Closed
jirenius opened this issue Dec 5, 2019 · 3 comments
Closed

CORS Support #141

jirenius opened this issue Dec 5, 2019 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@jirenius
Copy link
Collaborator

jirenius commented Dec 5, 2019

Issue

Resgate should have a configuration to enable CORS support for the REST API.

Solution

Alternative 1: Simple CORS setting

A boolean flag --cors would enable the adding of the HTTP header to the REST API:

Access-Control-Allow-Origin: *

This would cover the most common use case.

Alternative 2: Allow Origin setting

A string flag --alloworigin https://resgate.io would enable the adding of the HTTP header, but with a custom origin:

Access-Control-Allow-Origin: https://resgate.io

This would allow for a more flexible configuration.

Alternative 3: Header setting

A repeatable string flag that allows custom headers to be added to the response:

--header "Access-Control-Allow-Origin: *" --header "Custom-Header: foo"

This would allow full flexibility, while making it less obvious how to add CORS support.

Note: Added headers should be applied for both WS and HTTP, while the Access-Control-Allow-Origin header may be skipped on WS responses.

@jirenius jirenius added the enhancement New feature or request label Dec 5, 2019
@psiservices-dharrison
Copy link

psiservices-dharrison commented Dec 5, 2019

Option#3 seems the most flexible. My second choice would be Option#2.
For an edge case, would there be a way to support multiple domains in the origin/CORS allow header, without just using the wildcard *?

@jirenius
Copy link
Collaborator Author

jirenius commented Dec 6, 2019

@psiservices-dharrison Good question.
The header spec only allows a single domain in a response. By using Option#2, with the addition of allowing multiple flags (or possibly a single semi-colon separated string):

-alloworigin https://resgate.io -alloworigin https://example.com

Resgate could verify that the Origin header matches one of Resgate's allowed origins, and returning that origin in the Access-Control-Allow-Origin header, including Vary: Origin.

See: https://stackoverflow.com/questions/1653308/access-control-allow-origin-multiple-origin-domains

I think I prefer that option.
Option#3 might sound good, but in reality you seldom want to add a static header. Better to make specific (and dynamic) solutions to specific needs... like Option#2.

@jirenius jirenius self-assigned this Mar 12, 2020
jirenius added a commit that referenced this issue Mar 13, 2020
jirenius added a commit that referenced this issue Mar 13, 2020
Enforced content-type for same-origin setting.
jirenius added a commit that referenced this issue Mar 18, 2020
@jirenius
Copy link
Collaborator Author

Resolved in #149

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

No branches or pull requests

2 participants