How can I prevent Chrome from enforcing CORS for one specific file:// URL?

5

Context: I'm trying to run a local copy of this Diceware password generation site, and I'm currently getting a non-functional page with no CSS. Inspect Element tells me that most of the webpage is getting blocked due to CORS policy. I know there's ways around this; a similar question talks about how launching Chrome with --disable-web-security --user-data-dir or running a web-server using Python will allow one to achieve the intended results.

If possible, I'd really rather not do any of that, and instead just be able to double-click on the index.html file and have it work. Is there a modification I can make to my current Chrome installation that will make this possible? I've been trying to make this extension do what I want it to do, but even when it's set to allow everything, it still doesn't seem to work.

I'd prefer a solution that allows me to whitelist just this one local file and/or its containing directory, but just about anything is fine so long as it A) doesn't cause security issues when browsing the web itself and B) doesn't require special effort (e.g. launching a web-sever on my machine) to view this page.

p-lucero

Posted 2017-06-10T05:12:53.007

Reputation: 111

Answers

6

As it so often happens, I've found an answer almost as soon as I've gone to ask for help. Not perfect, but it works okay. Adding --allow-file-access-from-files --allow-file-access --allow-cross-origin-auth-prompt to Chrome's launch flags (which, to my understanding, allows files on one's local machine to be opened, to open other local files, and to bypass CORS policy) accomplishes basically what I want.

This does still allow all local files to do this, so it isn't perfect, but it's much better than allowing any file on either the local machine or the Web to do so. Putting this here if anybody else is searching for a similar answer, although I'm still searching for a better answer if one happens to exist.

p-lucero

Posted 2017-06-10T05:12:53.007

Reputation: 111

great, thank you! Could you also explain how to add these to Chrome launch flags? – zwolin – 2018-09-26T16:48:23.207

@zwolin sorry for the delayed reply. On Windows 10, right-click on the Chrome icon, then right-click on Google Chrome, then click Properties. In the Target field, append the launch flags. If you're using a desktop shortcut instead of a taskbar icon, you can also probably just right-click on it directly and click Properties, bypassing a couple of taskbar-specific steps. – p-lucero – 2018-10-28T17:17:01.110