File tree 7 files changed +38
-0
lines changed
7 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 97
97
"webpack-dev-middleware" : " ~1.12.0" ,
98
98
"webpack-dev-server" : " ~2.7.1" ,
99
99
"webpack-merge" : " ^4.1.0" ,
100
+ "webpack-subresource-integrity" : " ^1.0.1" ,
100
101
"zone.js" : " ^0.8.14"
101
102
},
102
103
"devDependencies" : {
Original file line number Diff line number Diff line change @@ -184,6 +184,13 @@ export const baseBuildCommandOptions: any = [
184
184
// aliases: ['eac'], // We should not have shorthand aliases for experimental flags.
185
185
description : '(Experimental) Use new Angular Compiler (Angular version 5 and greater only).' ,
186
186
default : AngularCompilerPlugin . isSupported ( )
187
+ } ,
188
+ {
189
+ name : 'subresource-integrity' ,
190
+ type : Boolean ,
191
+ default : false ,
192
+ aliases : [ 'sri' ] ,
193
+ description : 'Enables the use of subresource integrity validation.'
187
194
}
188
195
] ;
189
196
Original file line number Diff line number Diff line change @@ -26,4 +26,5 @@ export interface BuildOptions {
26
26
buildOptimizer ?: boolean ;
27
27
namedChunks ?: boolean ;
28
28
experimentalAngularCompiler ?: boolean ;
29
+ subresourceIntegrity ?: boolean ;
29
30
}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import * as fs from 'fs';
2
2
import * as webpack from 'webpack' ;
3
3
import * as path from 'path' ;
4
4
const HtmlWebpackPlugin = require ( 'html-webpack-plugin' ) ;
5
+ const SubresourceIntegrityPlugin = require ( 'webpack-subresource-integrity' ) ;
5
6
6
7
import { packageChunkSort } from '../../utilities/package-chunk-sort' ;
7
8
import { BaseHrefWebpackPlugin } from '../../lib/base-href-webpack' ;
@@ -60,7 +61,16 @@ export function getBrowserConfig(wco: WebpackConfigOptions) {
60
61
} ) ) ;
61
62
}
62
63
64
+ if ( buildOptions . subresourceIntegrity ) {
65
+ extraPlugins . push ( new SubresourceIntegrityPlugin ( {
66
+ hashFuncNames : [ 'sha384' ]
67
+ } ) ) ;
68
+ }
69
+
63
70
return {
71
+ output : {
72
+ crossOriginLoading : buildOptions . subresourceIntegrity ? 'anonymous' : false
73
+ } ,
64
74
plugins : [
65
75
new HtmlWebpackPlugin ( {
66
76
template : path . resolve ( appRoot , appConfig . index ) ,
Original file line number Diff line number Diff line change 81
81
"webpack-dev-middleware" : " ~1.12.0" ,
82
82
"webpack-dev-server" : " ~2.7.1" ,
83
83
"webpack-merge" : " ^4.1.0" ,
84
+ "webpack-subresource-integrity" : " ^1.0.1" ,
84
85
"zone.js" : " ^0.8.14"
85
86
},
86
87
"optionalDependencies" : {
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ const angularCliPlugins = require('../plugins/webpack');
21
21
22
22
const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
23
23
const HtmlWebpackPlugin = require ( 'html-webpack-plugin' ) ;
24
+ const SubresourceIntegrityPlugin = require ( 'webpack-subresource-integrity' ) ;
24
25
const SilentError = require ( 'silent-error' ) ;
25
26
const CircularDependencyPlugin = require ( 'circular-dependency-plugin' ) ;
26
27
const ConcatPlugin = require ( 'webpack-concat-plugin' ) ;
@@ -242,6 +243,10 @@ class JsonWebpackSerializer {
242
243
args = this . _uglifyjsPlugin ( plugin ) ;
243
244
this . variableImports [ 'uglifyjs-webpack-plugin' ] = 'UglifyJsPlugin' ;
244
245
break ;
246
+ case SubresourceIntegrityPlugin :
247
+ this . variableImports [ 'webpack-subresource-integrity' ] = 'SubresourceIntegrityPlugin' ;
248
+ break ;
249
+
245
250
default :
246
251
if ( plugin . constructor . name == 'AngularServiceWorkerPlugin' ) {
247
252
this . _addImport ( '@angular/service-worker/build/webpack' , plugin . constructor . name ) ;
Original file line number Diff line number Diff line change
1
+ import { expectFileToMatch } from '../../utils/fs' ;
2
+ import { ng } from '../../utils/process' ;
3
+ import { expectToFail } from '../../utils/utils' ;
4
+
5
+ const integrityRe = / i n t e g r i t y = " \w + - [ A - Z a - z 0 - 9 \/ \+ = ] + " / ;
6
+
7
+ export default async function ( ) {
8
+ return ng ( 'build' )
9
+ . then ( ( ) => expectToFail ( ( ) =>
10
+ expectFileToMatch ( 'dist/index.html' , integrityRe ) ) )
11
+ . then ( ( ) => ng ( 'build' , '--sri' ) )
12
+ . then ( ( ) => expectFileToMatch ( 'dist/index.html' , integrityRe ) ) ;
13
+ }
You can’t perform that action at this time.
0 commit comments