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
  • Loading branch information
alan-agius4 authored and angular-robot[bot] committed Feb 24, 2023
1 parent 2d3ad20 commit d4c4508
Showing 1 changed file with 3 additions and 3 deletions.
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 d4c4508

Please sign in to comment.