When I was making my PicoBlaze Simulator in JavaScript, I added 6 examples of how to use it. Those examples are on my GitHub profile, they are the .psm
(PicoBlaze Assembly) files. I decided not to hard-code the links to those .psm
files in my JavaScript, but to write a JSON file containing the links to them. However, I remember that browsers would not allow me to fetch
that examples.json
file from raw.githubusercontent.com
, that I had to copy examples.json
from my GitHub profile to my website in order to be able to fetch
it. Nevertheless, browsers do allow me to fetch
the .psm
files from my GitHub profile. Why is it so?
What is the threat model because of which browsers do not allow one to fetch
.json
files from raw.githubusercontent.com
? I understand that it is not a good idea to take JavaScript .js
files directly from somebody's GitHub profile: files on somebody's GitHub profile are not supposed to be well-tested (That's why you are not supposed to download the source code of some program from GitHub to build it, as many websites warn you, "There can quite possibly be bugs, in fact, the code might not even compile."). Furthermore, one who owns that file (and browsers cannot know it is me) could easily do a cross-site scripting attack on every website that uses that JavaScript if that were allowed. But .json
files are not executable JavaScript, they cannot contain cross-site scripting attacks. So, why aren't browsers allowing us to fetch
.json
files from raw.githubusercontent.com
?
In my Bachelor Thesis, I speculate that that decision dates back to the time when JSON was parsed using eval
(rather than JSON.parse
), so that somebody could indeed make a cross-site scripting attack by modifying the .json
file to contain invalid JSON (which JSON.parse
would reject, but eval
would accept). Is that correct?
fetch('https://raw.githubusercontent.com/path/to/something.json')').then((response) => response.json()).then((json) => console.log(json));
is fetching the JSON from GitHub and printing it to the console. Could you have an own Content Security Policy in place preventing the fetch?fetch("https://raw.githubusercontent.com/FlatAssembler/PicoBlaze_Simulator_in_JS/master/examples.json", {mode: "no-cors"});
This results in the error message:Cross-Origin Read Blocking (CORB) blocked cross-origin response https://raw.githubusercontent.com/FlatAssembler/PicoBlaze_Simulator_in_JS/master/examples.json with MIME type text/plain. See https://www.chromestatus.com/feature/5629709824032768 for more details.