File tree 2 files changed +16
-0
lines changed
packages/@angular/cli/models/webpack-configs
2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import { WebpackConfigOptions } from '../webpack-config';
10
10
const ConcatPlugin = require ( 'webpack-concat-plugin' ) ;
11
11
const ProgressPlugin = require ( 'webpack/lib/ProgressPlugin' ) ;
12
12
const CircularDependencyPlugin = require ( 'circular-dependency-plugin' ) ;
13
+ const SilentError = require ( 'silent-error' ) ;
13
14
14
15
15
16
/**
@@ -94,6 +95,13 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
94
95
asset . output = asset . output || '' ;
95
96
asset . glob = asset . glob || '' ;
96
97
98
+ // Prevent asset configurations from writing outside of the output path
99
+ const fullOutputPath = path . resolve ( buildOptions . outputPath , asset . output ) ;
100
+ if ( ! fullOutputPath . startsWith ( path . resolve ( buildOptions . outputPath ) ) ) {
101
+ const message = 'An asset cannot be written to a location outside of the output path.' ;
102
+ throw new SilentError ( message ) ;
103
+ }
104
+
97
105
// Ensure trailing slash.
98
106
if ( isDirectory ( path . resolve ( asset . input ) ) ) {
99
107
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