Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -12,6 +12,7 @@ import { readTsconfig } from '../../utilities/read-tsconfig';
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 @@ -96,6 +97,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