File tree 2 files changed +15
-0
lines changed
packages/@angular/cli/models/webpack-configs
2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { readTsconfig } from '../../utilities/read-tsconfig';
12
12
const ConcatPlugin = require ( 'webpack-concat-plugin' ) ;
13
13
const ProgressPlugin = require ( 'webpack/lib/ProgressPlugin' ) ;
14
14
const CircularDependencyPlugin = require ( 'circular-dependency-plugin' ) ;
15
+ const SilentError = require ( 'silent-error' ) ;
15
16
16
17
17
18
/**
@@ -96,6 +97,12 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
96
97
asset . output = asset . output || '' ;
97
98
asset . glob = asset . glob || '' ;
98
99
100
+ // Prevent asset configurations from writing outside of the output path
101
+ const fullOutputPath = path . resolve ( buildOptions . outputPath , asset . output ) ;
102
+ if ( ! fullOutputPath . startsWith ( path . resolve ( buildOptions . outputPath ) ) ) {
103
+ throw new SilentError ( 'An asset cannot be written to a location outside of the output path.' ) ;
104
+ }
105
+
99
106
// Ensure trailing slash.
100
107
if ( isDirectory ( path . resolve ( asset . input ) ) ) {
101
108
asset . input += '/' ;
Original file line number Diff line number Diff line change @@ -26,6 +26,14 @@ export default function () {
26
26
'./src/output-asset.txt' : 'output-asset.txt' ,
27
27
'./node_modules/some-package/node_modules-asset.txt' : 'node_modules-asset.txt' ,
28
28
} ) )
29
+ // Add invalid asset config in .angular-cli.json.
30
+ . then ( ( ) => updateJsonFile ( '.angular-cli.json' , configJson => {
31
+ const app = configJson [ 'apps' ] [ 0 ] ;
32
+ app [ 'assets' ] = [
33
+ { 'glob' : '**/*' , 'input' : '../node_modules/some-package/' , 'output' : '../package-folder' }
34
+ ] ;
35
+ } ) )
36
+ . then ( ( ) => expectToFail ( ( ) => ng ( 'build' ) ) )
29
37
// Add asset config in .angular-cli.json.
30
38
. then ( ( ) => updateJsonFile ( '.angular-cli.json' , configJson => {
31
39
const app = configJson [ 'apps' ] [ 0 ] ;
You can’t perform that action at this time.
0 commit comments