Skip to content

Commit 32e2e3f

Browse files
clydinfilipesilva
authored andcommitted
fix(@angular/cli): ensure asset output is within the output path
1 parent ddeb959 commit 32e2e3f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

packages/@angular/cli/models/webpack-configs/common.ts

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { WebpackConfigOptions } from '../webpack-config';
1010
const ConcatPlugin = require('webpack-concat-plugin');
1111
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
1212
const 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 += '/';

tests/e2e/tests/build/assets.ts

+8
Original file line numberDiff line numberDiff 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];

0 commit comments

Comments
 (0)