In a typical module script
<script type="module" crossorigin="use-credentials">
import {App} from './js/app.js';
const app = new App();
app.init();
</script>
Chrome, Safari and Edge have no issues loading it and cookies are sent with request to js/app.js
. FireFox 58 (with dom.moduleScripts.enabled
set to true) does not attach cookies. Even those not marked HttpOnly
. Chrome doesn't send them if use-credentials
is not specified.
As many web apps respond with 302 redirect to login page, typical reaction in the console is Loading failed for the <script> with source “http://localhost/js/app.js”.
or similar.
Of course, there are many ways to resolve it on the server side: allow JS modules to not require security checks, or place an auth token into the URL query. But it doesn't seem right.
What I am trying to understand, is there a definitive guide to the logic behind it? It used to be requests to the same origin, regardless of resource type, were carrying all cookies with them. Why would it be different for modules? Is there a magic attribute that makes it behave like the usual <script type="text/javascript" src=...></script>
in regards to cookies?