Dynamic imports are not controlled by your CSP

Posted . Visible to the public.

You might wonder which CSP directive applies when an allowed script makes a dynamic import:

await import('other-script.js')

The answer is that dynamic imports are always allowed regardless of your Content-Security-Policy header. Neither script-src nor connect-src apply.

Should I worry about this?

It would require some strange code for user input to make it into an import() argument.
I wouldn't lose sleep over this.

Profile picture of Henning Koch
Henning Koch
Last edit
Henning Koch
Keywords
content-security-policy
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2026-03-18 14:59)