Skip to content

Commit

Permalink
fix(@angular/cli): prevents using assets from outside the project
Browse files Browse the repository at this point in the history
This is a security risk. Think reading things from the home directory.
  • Loading branch information
hansl committed Nov 20, 2017
1 parent 535c85f commit 64c6031
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/@angular/cli/models/webpack-configs/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
}
}

// Prevent asset configurations from reading files outside of the project.
if (!asset.input.startsWith(projectRoot)) {
const message = 'An asset cannot be read from a location outside the project.';
throw new SilentError(message);
}

// Ensure trailing slash.
if (isDirectory(path.resolve(asset.input))) {
asset.input += '/';
Expand Down
9 changes: 9 additions & 0 deletions tests/e2e/tests/build/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ export default function () {
}))
.then(() => expectToFail(() => ng('build')))

// This asset should also fail from reading from outside the project.
.then(() => updateJsonFile('.angular-cli.json', configJson => {
const app = configJson['apps'][0];
app['assets'] = [
{ 'glob': '**/*', 'input': '/temp-folder/outside/of/project', 'output': 'temp' }
];
}))
.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 64c6031

Please sign in to comment.