Skip to content

Commit 9a5609a

Browse files
committedFeb 24, 2023
fix(@angular-devkit/build-angular): improve parsing of error messages
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)
1 parent 69390ae commit 9a5609a

File tree

1 file changed

+3
-3
lines changed
  • packages/angular_devkit/build_angular/src/webpack/utils

1 file changed

+3
-3
lines changed
 

‎packages/angular_devkit/build_angular/src/webpack/utils/stats.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,9 @@ export function statsErrorsToString(
412412
// In most cases webpack will add stack traces to error messages.
413413
// This below cleans up the error from stacks.
414414
// See: https://github.com/webpack/webpack/issues/15980
415-
const message = statsConfig.errorStack
416-
? error.message
417-
: /[\s\S]+?(?=\n+\s+at\s)/.exec(error.message)?.[0] ?? error.message;
415+
const index = error.message.search(/[\n\s]+at /);
416+
const message =
417+
statsConfig.errorStack || index === -1 ? error.message : error.message.substring(0, index);
418418

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

0 commit comments

Comments
 (0)
Please sign in to comment.