Skip to content
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

always fallback legacy build when CSP #5919

Closed
7 tasks done
yoyo930021 opened this issue Dec 1, 2021 · 5 comments · Fixed by #6535
Closed
7 tasks done

always fallback legacy build when CSP #5919

yoyo930021 opened this issue Dec 1, 2021 · 5 comments · Fixed by #6535

Comments

@yoyo930021
Copy link
Contributor

yoyo930021 commented Dec 1, 2021

Describe the bug

We use this line for detecting browser support.

const dynamicFallbackInlineCode = `!function(){try{new Function("m","return import(m)")}catch(o){console.warn("vite: loading legacy build because dynamic import is unsupported, syntax error above should be ignored");var e=document.getElementById("${legacyPolyfillId}"),n=document.createElement("script");n.src=e.src,n.onload=function(){${systemJSInlineCode}},document.body.appendChild(n)}}();`

but new Function code doesn't allow when CSP defaults.
So the browser will always fallback.
CSP hash can't ignore unsafe-eval.

截圖 2021-12-01 下午7 10 43

Reproduction

HTTP server header

Content-Security-Policy: default-src 'self'

And Using @vite/plugin-legacy

Project: https://github.com/yoyo930021/vite-legacy-csp-bug

System Info

System:
    OS: macOS 11.6
    CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
    Memory: 2.49 GB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.18.1 - ~/.volta/tools/image/node/14.18.1/bin/node
    Yarn: 2.4.2 - ~/.volta/tools/image/yarn/1.22.10/bin/yarn
    npm: 7.22.0 - ~/.volta/tools/image/npm/7.22.0/bin/npm
  Browsers:
    Edge: 96.0.1054.34
    Firefox Developer Edition: 95.0
    Firefox Nightly: 96.0a1
    Safari: 15.0

Used Package Manager

yarn

Logs

No response

Validations

@yoyo930021 yoyo930021 changed the title always fallback legacy bundle when CSP open always fallback legacy bundle when CSP Dec 1, 2021
@Jax-p
Copy link

Jax-p commented Jan 6, 2022

Did you find any walkaround for this?

@yoyo930021
Copy link
Contributor Author

Did you find any walkaround for this?

No, I allow unsafe-eval for temp.
But I have some idea to fix it. Maybe I will add a PR.

@yoyo930021 yoyo930021 changed the title always fallback legacy bundle when CSP always fallback legacy build when CSP Jan 17, 2022
@yoyo930021
Copy link
Contributor Author

yoyo930021 commented Jan 17, 2022

Did you find any walkaround for this?

No, I allow unsafe-eval for temp. But I have some idea to fix it. Maybe I will add a PR.

I open a PR about this. #6535
Maybe someone can test it.

@yoyo930021
Copy link
Contributor Author

Do we have any release plans?

@patak-dev
Copy link
Member

We will release it in tandem with vite 2.9, hopefully this week

@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants