@@ -16,6 +16,7 @@ import { InlineCriticalCssProcessor } from './inline-critical-css';
16
16
import { InlineFontsProcessor } from './inline-fonts' ;
17
17
import { addNgcmAttribute } from './ngcm-attribute' ;
18
18
import { addNonce } from './nonce' ;
19
+ import { autoCsp } from './auto-csp' ;
19
20
20
21
type IndexHtmlGeneratorPlugin = (
21
22
html : string ,
@@ -43,6 +44,7 @@ export interface IndexHtmlGeneratorOptions {
43
44
cache ?: NormalizedCachedOptions ;
44
45
imageDomains ?: string [ ] ;
45
46
generateDedicatedSSRContent ?: boolean ;
47
+ autoCsp ?: boolean ;
46
48
}
47
49
48
50
export type IndexHtmlTransform = ( content : string ) => Promise < string > ;
@@ -86,6 +88,11 @@ export class IndexHtmlGenerator {
86
88
this . csrPlugins . push ( addNgcmAttributePlugin ( ) ) ;
87
89
this . ssrPlugins . push ( addEventDispatchContractPlugin ( ) , addNoncePlugin ( ) ) ;
88
90
}
91
+
92
+ // Auto-CSP (as the last step)
93
+ if ( options . autoCsp ) {
94
+ this . csrPlugins . push ( autoCspPlugin ( ) ) ;
95
+ }
89
96
}
90
97
91
98
async process ( options : IndexHtmlGeneratorProcessOptions ) : Promise < IndexHtmlProcessResult > {
@@ -198,6 +205,10 @@ function addNoncePlugin(): IndexHtmlGeneratorPlugin {
198
205
return ( html ) => addNonce ( html ) ;
199
206
}
200
207
208
+ function autoCspPlugin ( ) : IndexHtmlGeneratorPlugin {
209
+ return ( html ) => autoCsp ( html ) ;
210
+ }
211
+
201
212
function postTransformPlugin ( { options } : IndexHtmlGenerator ) : IndexHtmlGeneratorPlugin {
202
213
return async ( html ) => ( options . postTransform ? options . postTransform ( html ) : html ) ;
203
214
}
0 commit comments