mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 11:15:14 +00:00
allow scripts to contain a CSP nonce
This commit is contained in:
@@ -524,9 +524,12 @@ function get_page_handler(
|
||||
styles = (css && css.code ? `<style>${css.code}</style>` : '');
|
||||
}
|
||||
|
||||
// users can set a CSP nonce using res.locals.nonce
|
||||
const nonceAttr = (res.locals && res.locals.nonce) ? ` nonce="${res.locals.nonce}"` : '';
|
||||
|
||||
const body = template()
|
||||
.replace('%sapper.base%', () => `<base href="${req.baseUrl}/">`)
|
||||
.replace('%sapper.scripts%', () => `<script>${script}</script>`)
|
||||
.replace('%sapper.scripts%', () => `<script${nonceAttr}>${script}</script>`)
|
||||
.replace('%sapper.html%', () => html)
|
||||
.replace('%sapper.head%', () => `<noscript id='sapper-head-start'></noscript>${head}<noscript id='sapper-head-end'></noscript>`)
|
||||
.replace('%sapper.styles%', () => styles);
|
||||
|
||||
Reference in New Issue
Block a user