Skip to content

Commit 12ce7eb

Browse files
authored
fix: add CSP hashes/nonces to inline styles when using (#13232)
1 parent 64c8e04 commit 12ce7eb

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

.changeset/angry-geckos-dream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: add CSP hashes/nonces to inline styles when using `bundleStrategy: 'inline'`

packages/kit/src/runtime/server/page/csp.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,6 @@ class BaseProvider {
186186
this.#style_src.push(source);
187187
}
188188

189-
if (this.#style_src_needs_csp) {
190-
this.#style_src.push(source);
191-
}
192-
193189
if (this.#style_src_attr_needs_csp) {
194190
this.#style_src_attr.push(source);
195191
}

packages/kit/src/runtime/server/page/render.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,18 @@ export async function render_response({
228228
return `${assets}/${path}`;
229229
};
230230

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');
237235

236+
if (style) {
238237
const attributes = __SVELTEKIT_DEV__ ? [' data-sveltekit'] : [];
239238
if (csp.style_needs_nonce) attributes.push(` nonce="${csp.nonce}"`);
240239

241-
csp.add_style(content);
240+
csp.add_style(style);
242241

243-
head += `\n\t<style${attributes.join('')}>${content}</style>`;
242+
head += `\n\t<style${attributes.join('')}>${style}</style>`;
244243
}
245244

246245
for (const dep of stylesheets) {

0 commit comments

Comments
 (0)