@@ -12,28 +12,31 @@ import type {SafeHtml} from '../../../types/internal';
1212 * Renders tag `<head>`.
1313 * @internal
1414 */
15- export const renderHead = ( reportFileName : string ) : SafeHtml => {
15+ export const renderHead = ( reportFileName : string , imgCspHosts : string ) : SafeHtml => {
1616 const renderedScript = renderScript ( ) ;
1717 const renderedStyle = renderStyle ( ) ;
1818
1919 const scriptContent = getContentFromRenderedElement ( renderedScript ) ;
2020 const styleContent = getContentFromRenderedElement ( renderedStyle ) ;
2121
22- const cspStyleHash = getCspHash ( styleContent ) ;
2322 const cspScriptHash = getCspHash ( scriptContent ) ;
23+ const cspStyleHash = getCspHash ( styleContent ) ;
24+
25+ const cspContent = [
26+ "default-src 'self';" ,
27+ `img-src 'self' data: ${ imgCspHosts } ;` ,
28+ `script-src '${ cspScriptHash } ';` ,
29+ `style-src '${ cspStyleHash } ';` ,
30+ ] ;
2431
25- const safeCspStyleHash = createSafeHtmlWithoutSanitize `${ cspStyleHash } ` ;
26- const safeCspScriptHash = createSafeHtmlWithoutSanitize `${ cspScriptHash } ` ;
32+ const safeCspContent = createSafeHtmlWithoutSanitize `${ cspContent . join ( ' ' ) } ` ;
2733
2834 return sanitizeHtml `
2935<head>
3036 <meta charset="utf-8" />
3137 <meta name="viewport" content="width=device-width, initial-scale=1" />
3238 <meta name="description" content="${ reportFileName } " />
33- <meta
34- http-equiv="Content-Security-Policy"
35- content="default-src 'self'; img-src 'self' data:; script-src '${ safeCspScriptHash } '; style-src '${ safeCspStyleHash } ';"
36- />
39+ <meta http-equiv="Content-Security-Policy" content="${ safeCspContent } " />
3740 <title>${ reportFileName } </title>
3841 ${ renderFavicon ( ) }
3942 ${ renderedStyle }
0 commit comments