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 set multiple domains #621

Closed
NKid opened this issue Oct 27, 2021 · 0 comments · Fixed by #628
Closed

CORS set multiple domains #621

NKid opened this issue Oct 27, 2021 · 0 comments · Fixed by #628

Comments

@NKid
Copy link

NKid commented Oct 27, 2021

Describe the bug
prest.toml

[cors]
alloworigin = ["https://www.domain1.com", "https://www.domain2.com"]

Frontend using js fetch call pREST in domain1's webpage, it failed.
Firefox show these messages.

  • Reason: CORS header ‘Access-Control-Allow-Origin’ does not match ‘https://www.domain1.com,https://www.domain2.com’
  • Reason: CORS request did not succeed

But when I using this setting, it works.

[cors]
alloworigin = ["https://www.domain1.com"]

To Reproduce
js fetch

let headers = new Headers();
headers.set('Authorization', 'Bearer {token}');
headers.set('Accept','application/json');

fetch('https://www.myserver.com/prest/public/prest_users', {
    method: 'GET',
    mode: 'cors',
    headers: headers
}).then((response) => {
    return response.json();
}).then((jsonData) => {
    console.log(jsonData);
});

Expected behavior
Return table data (JSON)

Desktop (please complete the following information):

  • pREST version (or commit ref): v1.0.10
  • pREST endpoint: /prest/public/prest_users
  • PostgreSQL version: docker image postgres:13-alpine
  • OS: [e.g. Debian Tid]: apline
  • Go version:
  • Log gist:

Additional context
I think the header Access-Control-Allow-Origin sholud only return current request domain.
Here is pseudocode to present my thoughts.

var allowOrigins = ["https://www.domain1.com","https://www.domain2.com"];
var origin = Request.Headers["Origin"];
if (allowOrigins.includes(orgin)) {
  Response.AddHeader("Access-Control-Allow-Origin", origin);
}
@arxdsilva arxdsilva added the bug label Oct 27, 2021
@avelino avelino added this to the API Server - v1.0.11 milestone Oct 28, 2021
avelino added a commit that referenced this issue Dec 3, 2021
ref: #621

Signed-off-by: Avelino <avelinorun@gmail.com>
avelino added a commit that referenced this issue Dec 3, 2021
ref: #621

Signed-off-by: Avelino <avelinorun@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants