HW-SWeL / Validata

Online frontend for ShEx-validator for restricted deployment environments
http://hw-swel.github.io/Validata/
MIT License
11 stars 2 forks source link

CORS header not being set #61

Open AlasdairGray opened 5 years ago

AlasdairGray commented 5 years ago

This issue was discovered when adding JSON-LD support to the validation and is captured in issue ShEx-Validator #36.

To reproduce the error, deploy Validata with the Bioschems configuration file, or use the deployment at http://www.macs.hw.ac.uk/~ajg33/BioschemasValidata/

Click on one of the examples which will add JSON-LD into the Input Data box. Validata should convert this into turtle for validation. If you look in the error console you will see Access to XMLHttpRequest at 'http://schema.org/' from origin 'http://www.macs.hw.ac.uk' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

What is going on is that when the Input Data box detects that the input is JSON-LD it tries to covert it to turtle. You can see this by entering the following

{
    "@type": "http://schema.org/Person",
    "name": "Jane Doe"
}

If you try the equivalent with an @context statement, then the system tries to pull in the context file dynamically. This fails with the CORS error

{
    "@context": "http://schema.org/",
    "@type": "http://schema.org/Person",
    "name": "Jane Doe"
  }

I have verified that schema.org is able to server the request properly. It is something in the request that is incorrect. I just can’t work out what.

kcmcleod commented 5 years ago

The CORS statement normally goes in the response header from the server and allows the data served to be used by applications from other sites.

Access to XMLHttpRequest at 'http://schema.org/' from origin 'http://www.macs.hw.ac.uk' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Reading the error it looks as though the server (http://schema.org) has no CORS statement in its response header. If this is true, it is a schema.org issue and not a Validator one.

The only to tell is to look at the response header. What is the URI that is being called?

AlasdairGray commented 5 years ago

There is something in the way that schema.org is set up that requires the client to send certain things in the header. There are some details at https://github.com/json-ld/json-ld.org/wiki/existing-contexts

When I use the Chrome CORS extension to inject the appropriate incantations it works. Just need to work out how to get the jQuery to inject them.