@@ -16,6 +16,7 @@ import { InlineCriticalCssProcessor } from './inline-critical-css';
1616import { InlineFontsProcessor } from './inline-fonts' ;
1717import { addNgcmAttribute } from './ngcm-attribute' ;
1818import { addNonce } from './nonce' ;
19+ import { autoCsp } from './auto-csp' ;
1920
2021type IndexHtmlGeneratorPlugin = (
2122 html : string ,
@@ -43,6 +44,7 @@ export interface IndexHtmlGeneratorOptions {
4344 cache ?: NormalizedCachedOptions ;
4445 imageDomains ?: string [ ] ;
4546 generateDedicatedSSRContent ?: boolean ;
47+ autoCsp ?: boolean ;
4648}
4749
4850export type IndexHtmlTransform = ( content : string ) => Promise < string > ;
@@ -86,6 +88,11 @@ export class IndexHtmlGenerator {
8688 this . csrPlugins . push ( addNgcmAttributePlugin ( ) ) ;
8789 this . ssrPlugins . push ( addEventDispatchContractPlugin ( ) , addNoncePlugin ( ) ) ;
8890 }
91+
92+ // Auto-CSP (as the last step)
93+ if ( options . autoCsp ) {
94+ this . csrPlugins . push ( autoCspPlugin ( ) ) ;
95+ }
8996 }
9097
9198 async process ( options : IndexHtmlGeneratorProcessOptions ) : Promise < IndexHtmlProcessResult > {
@@ -198,6 +205,10 @@ function addNoncePlugin(): IndexHtmlGeneratorPlugin {
198205 return ( html ) => addNonce ( html ) ;
199206}
200207
208+ function autoCspPlugin ( ) : IndexHtmlGeneratorPlugin {
209+ return ( html ) => autoCsp ( html ) ;
210+ }
211+
201212function postTransformPlugin ( { options } : IndexHtmlGenerator ) : IndexHtmlGeneratorPlugin {
202213 return async ( html ) => ( options . postTransform ? options . postTransform ( html ) : html ) ;
203214}
0 commit comments