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 @@ -12,6 +12,7 @@ import { readTsconfig } from '../../utilities/read-tsconfig';
1212const ConcatPlugin = require ( 'webpack-concat-plugin' ) ;
1313const ProgressPlugin = require ( 'webpack/lib/ProgressPlugin' ) ;
1414const CircularDependencyPlugin = require ( 'circular-dependency-plugin' ) ;
15+ const SilentError = require ( 'silent-error' ) ;
1516
1617
1718/**
@@ -96,6 +97,13 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
9697 asset . output = asset . output || '' ;
9798 asset . glob = asset . glob || '' ;
9899
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+ const message = 'An asset cannot be written to a location outside of the output path.' ;
104+ throw new SilentError ( message ) ;
105+ }
106+
99107 // Ensure trailing slash.
100108 if ( isDirectory ( path . resolve ( asset . input ) ) ) {
101109 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