periodo / periodo-client

Client to browse and edit PeriodO data
https://client.perio.do
Other
15 stars 2 forks source link

CORS support on servers we depend on #239

Open rybesh opened 4 years ago

rybesh commented 4 years ago

In modern web browsers, making requests from JavaScript (JS) to URLs with domains that differ from the one where the JavaScript originated is forbidden by default.

Servers that wish to allow JS requests from other domains can indicate this by setting an Access-Control-Allow-Origin header, e.g.

Access-Control-Allow-Origin: *

to allow JS requests from any domain.

Since JS applications working with linked data URLs need to be able to make GET requests to those URLs, in order to discover the resources to which they point, then it makes sense for both URL resolvers and linked data servers to set this header.

In order to ensure that JS on arbitrary domains can only read and not write to URL resolvers and linked data servers, it may also make sense to only allow GET requests by setting an Access-Control-Allow-Methods header, e.g.:

Access-Control-Allow-Methods: GET

Since a 302 Redirect (or other redirect) response is useless without the Location header, and browsers by default do not expose the Location header to JS, it also makes sense for URL resolvers to expose that header by setting an Access-Control-Expose-Headers header, e.g.:

Access-Control-Expose-Headers: Location

By setting these headers, URLs of linked data publishers and resolvers become usable from JS running in browsers, without compromising the security of their servers.

Unfortunately, more than six years after Cross-Origin Resource Sharing (CORS) became a W3C Recommendation, support for these CORS headers among major scholarly data publishers and resolvers is still poor.

rybesh commented 4 years ago
gbilder commented 4 years ago

Hello. Perhaps try this test for dx.doi.org/doi.org?

Or with curl:

curl -L -I 'Origin: http://www.example.com' -H 'Accept:application/vnd.citationstyles.csl+json' http://doi.org/10.1155/2013/564864
rybesh commented 4 years ago

Thanks @gbilder! I've updated the list to reflect that [dx.]doi.org do correctly support CORS.