Skip to content

Commit cd35330

Browse files
authoredNov 21, 2023
docs(legacy): clarify that csp hashes could change between minors (#15057)
1 parent 2116f0e commit cd35330

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed
 

‎packages/plugin-legacy/README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,15 @@ export default {
152152

153153
## Content Security Policy
154154

155-
The legacy plugin requires inline scripts for [Safari 10.1 `nomodule` fix](https://gist.github.com/samthor/64b114e4a4f539915a95b91ffd340acc), SystemJS initialization, and dynamic import fallback. If you have a strict CSP policy requirement, you will need to [add the corresponding hashes to your `script-src` list](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_inline_script):
155+
The legacy plugin requires inline scripts for [Safari 10.1 `nomodule` fix](https://gist.github.com/samthor/64b114e4a4f539915a95b91ffd340acc), SystemJS initialization, and dynamic import fallback. If you have a strict CSP policy requirement, you will need to [add the corresponding hashes to your `script-src` list](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_inline_script).
156+
157+
The hash values (without the `sha256-` prefix) can be retrieved via:
158+
159+
```js
160+
import { cspHashes } from '@vitejs/plugin-legacy'
161+
```
162+
163+
The current values are:
156164

157165
- `sha256-MS6/3FCg4WjP9gwgaBGwLpRCY6fZBgwmhVCdrPrNf3E=`
158166
- `sha256-tQjf8gvb2ROOMapIxFvFAYBeUJ0v1HCbOcSmDNXGtDo=`
@@ -163,11 +171,7 @@ The legacy plugin requires inline scripts for [Safari 10.1 `nomodule` fix](https
163171
Run `node --input-type=module -e "import {cspHashes} from '@vitejs/plugin-legacy'; console.log(cspHashes.map(h => 'sha256-'+h))"` to retrieve the value.
164172
-->
165173

166-
These values (without the `sha256-` prefix) can also be retrieved via
167-
168-
```js
169-
import { cspHashes } from '@vitejs/plugin-legacy'
170-
```
174+
Note that these values could change between minor versions. Thus, we recommend generating the CSP header from the exported `cspHashes` variable. If you copy the values manually, then you should pin the minor version using `~`.
171175

172176
When using the `regenerator-runtime` polyfill, it will attempt to use the `globalThis` object to register itself. If `globalThis` is not available (it is [fairly new](https://caniuse.com/?search=globalThis) and not widely supported, including IE 11), it attempts to perform dynamic `Function(...)` call which violates the CSP. To avoid dynamic `eval` in the absence of `globalThis` consider adding `core-js/proposals/global-this` to `additionalLegacyPolyfills` to define it.
173177

0 commit comments

Comments
 (0)
Please sign in to comment.