Skip to content

Commit 4b97518

Browse files
authored
Ignore stack frames over 1kb (#6627)
1 parent e6350d6 commit 4b97518

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

packages/browser/test/unit/tracekit/chromium.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,4 +547,30 @@ describe('Tracekit - Chrome Tests', () => {
547547
},
548548
});
549549
});
550+
551+
it('should drop frames that are over 1kb', () => {
552+
const LONG_STR = 'A'.repeat(1040);
553+
554+
const LONG_FRAME = {
555+
message: 'bad',
556+
name: 'Error',
557+
stack: `Error: bad
558+
at aha (http://localhost:5000/:39:5)
559+
at Foo.testMethod (http://localhost:5000/${LONG_STR}:44:7)
560+
at http://localhost:5000/:50:19`,
561+
};
562+
563+
const ex = exceptionFromError(parser, LONG_FRAME);
564+
565+
expect(ex).toEqual({
566+
value: 'bad',
567+
type: 'Error',
568+
stacktrace: {
569+
frames: [
570+
{ filename: 'http://localhost:5000/', function: '?', lineno: 50, colno: 19, in_app: true },
571+
{ filename: 'http://localhost:5000/', function: 'aha', lineno: 39, colno: 5, in_app: true },
572+
],
573+
},
574+
});
575+
});
550576
});

packages/utils/src/stacktrace.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ export function createStackParser(...parsers: StackLineParser[]): StackParser {
1616
const frames: StackFrame[] = [];
1717

1818
for (const line of stack.split('\n').slice(skipFirst)) {
19+
// Ignore lines over 1kb as they are unlikely to be stack frames.
20+
// Many of the regular expressions use backtracking which results in run time that increases exponentially with
21+
// input size. Huge strings can result in hangs/Denial of Service:
22+
// https://github.com/getsentry/sentry-javascript/issues/2286
23+
if (line.length > 1024) {
24+
continue;
25+
}
26+
1927
// https://github.com/getsentry/sentry-javascript/issues/5459
2028
// Remove webpack (error: *) wrappers
2129
const cleanedLine = line.replace(/\(error: (.*)\)/, '$1');

0 commit comments

Comments
 (0)