diff --git a/src/render/compose.js b/src/render/compose.js index 5e738cd4..ec4ef459 100644 --- a/src/render/compose.js +++ b/src/render/compose.js @@ -33,6 +33,19 @@ function injectAEMHtmlHeadEntries(daCtx, headNode, headHtmlStr) { const { org, site, orgSiteInPath } = daCtx; const aemHeadHtmlTree = fromHtml(headHtmlStr, { fragment: true }); + // the pipeline moves this meta to a response header and rewrites the placeholder + // nonce; drop both. + aemHeadHtmlTree.children = aemHeadHtmlTree.children.filter( + (node) => !(node.type === 'element' + && node.tagName === 'meta' + && node.properties?.['move-to-http-header'] !== undefined + && typeof node.properties?.content === 'string' + && node.properties.content.includes("'nonce-aem'")), + ); + selectAll('[nonce=aem]', aemHeadHtmlTree).forEach((n) => { + delete n.properties.nonce; + }); + // TODO: reuse fixUrlsWhenLocalDev from aemCtx.js instead of duplicating. if (orgSiteInPath) { const headScriptsAndLinks = selectAll( diff --git a/test/render/compose.test.js b/test/render/compose.test.js index 0bcd710f..41454a2d 100644 --- a/test/render/compose.test.js +++ b/test/render/compose.test.js @@ -66,4 +66,28 @@ describe('render compose', () => { assert.ok(!html.includes('urn:adobe:aue')); assert.ok(!html.includes('universal-editor-service')); }); + it('drops a CSP meta the pipeline would have moved to a header', async () => { + const cspHead = '' + + ''; + + const tree = await composeHtml(daCtx, aemCtx, '
content
content