4 ms·
| Also, the author makes a good point that `Access-Control-Allow-Origin: *` is pretty dangerous. But what is the alternative when you have a script that is goi
by takinola 7y ago
| Also, the author makes a good point that `Access-Control-Allow-Origin: *` is pretty dangerous.
But what is the alternative when you have a script that is going to be deployed on multiple sites that you do not control? Which origin do you specify? This is the scenario which always trips me up and results in kludgy workarounds.
- jrochkind1 7y agoI _think_ that is an the appropriate use for `Access-Control-Allow-Origin: `. It would be up to you that only the URL for such scripts (not your entire site) have `Access-Control-Allow-Origin: ` , and to make sure that there is nothing malicious JS can do with `Access-Control-Allow-Origin: *` at those particular URLs. Which is confusing to figure out, it's true, because the whole thing is confusing, indeed.
- zek 7y agoI think the generally accepted solution to this is to set the allowed origin dynamically (IIRC nginx can do this) by looking at the request host header on the options request. If the origin is in some allowed list then you return that origin in `Access-Control-Allow-Origin`