Skip to content

Commit

Permalink
fix(@angular/cli): ensure asset output is within the output path
Browse files Browse the repository at this point in the history
  • Loading branch information
clydin authored and filipesilva committed Sep 28, 2017
1 parent ddeb959 commit 32e2e3f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/@angular/cli/models/webpack-configs/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { WebpackConfigOptions } from '../webpack-config';
const ConcatPlugin = require('webpack-concat-plugin');
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const SilentError = require('silent-error');


/**
Expand Down Expand Up @@ -94,6 +95,13 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
asset.output = asset.output || '';
asset.glob = asset.glob || '';

// Prevent asset configurations from writing outside of the output path
const fullOutputPath = path.resolve(buildOptions.outputPath, asset.output);
if (!fullOutputPath.startsWith(path.resolve(buildOptions.outputPath))) {
const message = 'An asset cannot be written to a location outside of the output path.';
throw new SilentError(message);
}

// Ensure trailing slash.
if (isDirectory(path.resolve(asset.input))) {
asset.input += '/';
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/tests/build/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export default function () {
'./src/output-asset.txt': 'output-asset.txt',
'./node_modules/some-package/node_modules-asset.txt': 'node_modules-asset.txt',
}))
// Add invalid asset config in .angular-cli.json.
.then(() => updateJsonFile('.angular-cli.json', configJson => {
const app = configJson['apps'][0];
app['assets'] = [
{ 'glob': '**/*', 'input': '../node_modules/some-package/', 'output': '../package-folder' }
];
}))
.then(() => expectToFail(() => ng('build')))
// Add asset config in .angular-cli.json.
.then(() => updateJsonFile('.angular-cli.json', configJson => {
const app = configJson['apps'][0];
Expand Down

0 comments on commit 32e2e3f

Please sign in to comment.