Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): improve parsing of 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 #24771

(cherry picked from commit d4c4508)
  • Loading branch information
alan-agius4 committed Feb 24, 2023
1 parent 69390ae commit 9a5609a
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 9a5609a

Please sign in to comment.