File tree 3 files changed +12
-12
lines changed
packages/kit/src/runtime/server/page 3 files changed +12
-12
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @sveltejs/kit ' : patch
3
+ ---
4
+
5
+ fix: add CSP hashes/nonces to inline styles when using ` bundleStrategy: 'inline' `
Original file line number Diff line number Diff line change @@ -186,10 +186,6 @@ class BaseProvider {
186
186
this . #style_src. push ( source ) ;
187
187
}
188
188
189
- if ( this . #style_src_needs_csp) {
190
- this . #style_src. push ( source ) ;
191
- }
192
-
193
189
if ( this . #style_src_attr_needs_csp) {
194
190
this . #style_src_attr. push ( source ) ;
195
191
}
Original file line number Diff line number Diff line change @@ -228,19 +228,18 @@ export async function render_response({
228
228
return `${ assets } /${ path } ` ;
229
229
} ;
230
230
231
- if ( client . inline ?. style ) {
232
- head += `\n\t<style>${ client . inline . style } </style>` ;
233
- }
234
-
235
- if ( inline_styles . size > 0 ) {
236
- const content = Array . from ( inline_styles . values ( ) ) . join ( '\n' ) ;
231
+ // inline styles can come from `bundleStrategy: 'inline'` or `inlineStyleThreshold`
232
+ const style = client . inline
233
+ ? client . inline ?. style
234
+ : Array . from ( inline_styles . values ( ) ) . join ( '\n' ) ;
237
235
236
+ if ( style ) {
238
237
const attributes = __SVELTEKIT_DEV__ ? [ ' data-sveltekit' ] : [ ] ;
239
238
if ( csp . style_needs_nonce ) attributes . push ( ` nonce="${ csp . nonce } "` ) ;
240
239
241
- csp . add_style ( content ) ;
240
+ csp . add_style ( style ) ;
242
241
243
- head += `\n\t<style${ attributes . join ( '' ) } >${ content } </style>` ;
242
+ head += `\n\t<style${ attributes . join ( '' ) } >${ style } </style>` ;
244
243
}
245
244
246
245
for ( const dep of stylesheets ) {
You can’t perform that action at this time.
0 commit comments