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

Add CORS header to response #37

Open
klues opened this issue Feb 14, 2020 · 1 comment
Open

Add CORS header to response #37

klues opened this issue Feb 14, 2020 · 1 comment

Comments

@klues
Copy link

klues commented Feb 14, 2020

since the purpose of this script is to bypass CORS check, the response should contain CORS headers.

I've tried the script on my php server and requests from javascript didn't succeed because of missing CORS headers. After adding

header("Access-Control-Allow-Origin: *");

to the php file, everything works fine.

@avbentem
Copy link

avbentem commented Dec 21, 2020

One may need a bit more:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: *');
header('Access-Control-Allow-Methods: *');
header('Access-Control-Allow-Credentials: true');

Even more:

When responding to a credentialed request, the server must specify an origin in the value of the Access-Control-Allow-Origin header, instead of specifying the "*" wildcard.

(This also applies to including cookies.)

So, maybe:

header('Access-Control-Allow-Origin: ' . ($_SERVER['HTTP_ORIGIN'] ?? '*'));

Also, one may not want to delegate OPTIONS to the remote server, as that remote server may need authorization while the browser will not include any credentials for the OPTIONS request:

if ('OPTIONS' == $request_method) {
    http_response_code(200);
    exit;
}

since the purpose of this script is to bypass CORS check

Aside: the CORS headers are not needed when hosting this very proxy on the same domain as the web pages that make the requests. But given the configuration for $valid_requests hosting on the same domain is indeed not a requirement. (And I myself also needed to add those headers.)

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

2 participants