You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -272,3 +274,57 @@ The bundling system uses two different cache strategies:
272
274
-**Runtime cache**: Bundled scripts are served with 1-year cache headers since they are content-addressed by hash.
273
275
274
276
This dual approach ensures both build performance and reliable browser caching.
277
+
278
+
### Subresource Integrity (SRI)
279
+
280
+
Subresource Integrity (SRI) is a security feature that ensures scripts haven't been tampered with. When enabled, a cryptographic hash is calculated for each bundled script and added as an `integrity` attribute.
281
+
282
+
#### Enabling SRI
283
+
284
+
```ts [nuxt.config.ts]
285
+
exportdefaultdefineNuxtConfig({
286
+
scripts: {
287
+
assets: {
288
+
integrity: true, // Uses sha384 by default
289
+
}
290
+
}
291
+
})
292
+
```
293
+
294
+
#### Hash Algorithms
295
+
296
+
You can specify the hash algorithm:
297
+
298
+
```ts [nuxt.config.ts]
299
+
exportdefaultdefineNuxtConfig({
300
+
scripts: {
301
+
assets: {
302
+
integrity: 'sha384', // Default, recommended balance of security/size
303
+
// integrity: 'sha256', // Smaller hash
304
+
// integrity: 'sha512', // Strongest security
305
+
}
306
+
}
307
+
})
308
+
```
309
+
310
+
#### How It Works
311
+
312
+
When `integrity` is enabled:
313
+
314
+
1. During build, each bundled script's content is hashed
315
+
2. The hash is stored in the build cache for reuse
316
+
3. The `integrity` attribute is injected into the script tag
317
+
4. The `crossorigin="anonymous"` attribute is automatically added (required by browsers for SRI)
318
+
319
+
```html
320
+
<!-- Output with integrity enabled -->
321
+
<scriptsrc="/_scripts/abc123.js"
322
+
integrity="sha384-oqVuAfXRKap..."
323
+
crossorigin="anonymous"></script>
324
+
```
325
+
326
+
#### Security Benefits
327
+
328
+
-**Tamper detection**: Browser refuses to execute scripts if the hash doesn't match
329
+
-**CDN compromise protection**: Even if your CDN is compromised, modified scripts won't execute
330
+
-**Build-time verification**: Hash is calculated from the actual downloaded content
Enable automatic Subresource Integrity (SRI) hash generation for bundled scripts. When enabled, calculates a cryptographic hash of each bundled script and injects the `integrity` attribute along with `crossorigin="anonymous"`.
73
+
74
+
See the [Bundling - Subresource Integrity](/docs/guides/bundling#subresource-integrity-sri) documentation for more details.
0 commit comments