diff --git a/packages/angular/build/src/utils/index-file/auto-csp.ts b/packages/angular/build/src/utils/index-file/auto-csp.ts index 07e183aaba36..8a5e339a9ac4 100644 --- a/packages/angular/build/src/utils/index-file/auto-csp.ts +++ b/packages/angular/build/src/utils/index-file/auto-csp.ts @@ -92,7 +92,7 @@ export async function autoCsp(html: string, unsafeEval = false): Promise * loader script to the collection of hashes to add to the tag CSP. */ function emitLoaderScript() { - const loaderScript = createLoaderScript(scriptContent); + const loaderScript = createLoaderScript(scriptContent, /* enableTrustedTypes = */ false); hashes.push(hashTextContent(loaderScript)); rewriter.emitRaw(``); scriptContent = []; @@ -152,7 +152,7 @@ export async function autoCsp(html: string, unsafeEval = false): Promise } } - if (tag.tagName === 'body' || tag.tagName === 'html') { + if (tag.tagName === 'head' || tag.tagName === 'body' || tag.tagName === 'html') { // Write the loader script if a string of @@ -96,13 +100,15 @@ describe('auto-csp', () => { const csps = getCsps(result); expect(csps.length).toBe(1); - expect(csps[0]).toMatch(ONE_HASH_CSP); + expect(csps[0]).toMatch(TWO_HASH_CSP); expect(result).toContain( // eslint-disable-next-line max-len - `var scripts = [['./main1.js', undefined, false, false],['./main2.js', undefined, true, false],['./main3.js', 'module', true, true]];`, + `var scripts = [['./main1.js', '', false, false],['./main2.js', '', true, false],['./main3.js', 'module', true, true]];`, ); - // Only one loader script is created. - expect(Array.from(result.matchAll(/`); + // Only two loader scripts are created. + expect(Array.from(result.matchAll(/ + + +
Some text
+ + + `); + + const csps = getCsps(result); + expect(csps.length).toBe(1); + expect(csps[0]).toMatch(ONE_HASH_CSP); + + expect(result).toContain( + // eslint-disable-next-line max-len + `document.lastElementChild.appendChild`, + ); + // Head loader script is in the head. + expect(result).toContain(``); + // Only one loader script is created. + expect(Array.from(result.matchAll(/