File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
packages/@angular/cli/models/webpack-configs Expand file tree Collapse file tree 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';
1010const ConcatPlugin = require ( 'webpack-concat-plugin' ) ;
1111const ProgressPlugin = require ( 'webpack/lib/ProgressPlugin' ) ;
1212const CircularDependencyPlugin = require ( 'circular-dependency-plugin' ) ;
13+ const SilentError = require ( 'silent-error' ) ;
1314
1415
1516/**
@@ -94,6 +95,13 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
9495 asset . output = asset . output || '' ;
9596 asset . glob = asset . glob || '' ;
9697
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+
97105 // Ensure trailing slash.
98106 if ( isDirectory ( path . resolve ( asset . input ) ) ) {
99107 asset . input += '/' ;
Original file line number Diff line number Diff line change @@ -26,6 +26,14 @@ export default function () {
2626 './src/output-asset.txt' : 'output-asset.txt' ,
2727 './node_modules/some-package/node_modules-asset.txt' : 'node_modules-asset.txt' ,
2828 } ) )
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' ) ) )
2937 // Add asset config in .angular-cli.json.
3038 . then ( ( ) => updateJsonFile ( '.angular-cli.json' , configJson => {
3139 const app = configJson [ 'apps' ] [ 0 ] ;
You can’t perform that action at this time.
0 commit comments