Skip to content

Commit 64c6031

Browse files
committed
fix(@angular/cli): prevents using assets from outside the project
This is a security risk. Think reading things from the home directory.
1 parent 535c85f commit 64c6031

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
112112
}
113113
}
114114

115+
// Prevent asset configurations from reading files outside of the project.
116+
if (!asset.input.startsWith(projectRoot)) {
117+
const message = 'An asset cannot be read from a location outside the project.';
118+
throw new SilentError(message);
119+
}
120+
115121
// Ensure trailing slash.
116122
if (isDirectory(path.resolve(asset.input))) {
117123
asset.input += '/';

tests/e2e/tests/build/assets.ts

+9
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ export default function () {
5555
}))
5656
.then(() => expectToFail(() => ng('build')))
5757

58+
// This asset should also fail from reading from outside the project.
59+
.then(() => updateJsonFile('.angular-cli.json', configJson => {
60+
const app = configJson['apps'][0];
61+
app['assets'] = [
62+
{ 'glob': '**/*', 'input': '/temp-folder/outside/of/project', 'output': 'temp' }
63+
];
64+
}))
65+
.then(() => expectToFail(() => ng('build')))
66+
5867
// Add asset config in .angular-cli.json.
5968
.then(() => updateJsonFile('.angular-cli.json', configJson => {
6069
const app = configJson['apps'][0];

0 commit comments

Comments
 (0)