Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): improve parsing or error messages
Browse files Browse the repository at this point in the history
Webpack errors can sometimes be several hundred of thousands of characters long as it may contain the entire bundle. This can cause a ReDoS. This change improves the way we parse and remove stack traces from error messages.

Closes angular#24771
  • Loading branch information
alan-agius4 committed Feb 24, 2023
1 parent 6335cf9 commit 4c402f7
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ export function statsErrorsToString(
// In most cases webpack will add stack traces to error messages.
// This below cleans up the error from stacks.
// See: https://github.com/webpack/webpack/issues/15980
const message = statsConfig.errorStack
? error.message
: /[\s\S]+?(?=\n+\s+at\s)/.exec(error.message)?.[0] ?? error.message;
const index = error.message.search(/[\n\s]+at /);
const message =
statsConfig.errorStack || index === -1 ? error.message : error.message.substring(0, index);

if (!/^error/i.test(message)) {
output += r('Error: ');
Expand Down

0 comments on commit 4c402f7

Please sign in to comment.