-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@vitejs/plugin-legacy CSP for blankDynamicImport does not work #4568
Comments
Bump! For anyone with a strict CSP policy, it is not possible to upgrade /cc @nulladdict since it broke in this commit: fc6d8f1 |
Hi, I'm not an expert on CSP usage, so this completely escaped me. First of all, when CSP blocks the dynamic import from loading, the main bundle still works, since import is there to only force syntax errors in certain browsers. We do still get the CSP error and network error logged into the console, which is not ideal though. I've tried providing the SHA hash for the import, but I couldn't make it work. I tried hashing different combinations of Adding I did manage to make it work by using Overall I see 2 ways of dealing with this:
|
Would it be possible to move the |
The import is there to prevent double executing of the bundle in a specific case where the bundled app doesn't use dynamic import and the browser doesn't support them but supports module tags. For this case I guess there's no need to perform an |
Is this approach valid? If this still raises the syntax error (so parsing is stopped) and avoids the CSP issue, this seems goods to me |
It only silences the network error after the import is blocked by the CSP, so it doesn't really avoid the issue, only reduces the amount of noise in the console |
And what is the issue with the import being blocked if we only need it for the syntax error, is this error surfaced in tools like web vitals or security audits? |
@nulladdict would wrapping the blank import in a function still trigger the syntax error for these browsers? function(){import('data:text/javascript,')} I wonder if we could trigger the syntax error without the actual call to |
I'm not too sure unfortunately... @nulladdict could the the script tag be injected with an |
@patak-js that's a good idea. I tried it inside Edge 18, Nevermind, the message was due to function statement requiring the function name. If I change it to expression like this I've made a draft PR with changes (#4767) |
Oh I hadn't noticed @patak-js's suggestion... great idea! Nice work both of you, thanks. |
Describe the bug
This code is rendered as part of a chunk rather than a standalone script tag so the sha CSP does not work for it.
Reproduction
Can supply if not obvious.
System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: