Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

fix(markdown-editor): bound paste link cue to kill ReDoS on large pastes

Sergey Kozyrenkob015f3ba98a2
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-paste.test.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-paste.test.ts
index 5b0655fa..1c9bf8b8 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-paste.test.ts
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-paste.test.ts
@@ -58,6 +58,15 @@ describe('shouldParseMarkdownOnPaste — markdown-parse plain text, defer rich s
it('keeps a paste inside a code context literal', () => {
expect(shouldParseMarkdownOnPaste('# x', '', true)).toBe(false);
});
+
+ it('scans the markdown cues in linear time on a large bracket-heavy paste (ReDoS guard)', () => {
+ const evil = '[x]'.repeat(50_000);
+ const started = performance.now();
+
+ shouldParseMarkdownOnPaste(evil, '<span>x</span>', false);
+
+ expect(performance.now() - started).toBeLessThan(150);
+ });
});
describe('MarkdownPaste — the parsed payload matches load (same tuned markdown layer)', () => {
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-paste.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-paste.ts
index 1ab5bde2..88a5d3d3 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-paste.ts
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-paste.ts
@@ -9,10 +9,13 @@ import { Plugin, PluginKey } from '@tiptap/pm/state';
// code literal.
const RICH_HTML_BLOCK = /<(?:h[1-6]|ul|ol|li|table|thead|tbody|tr|td|th|blockquote|pre|img|hr)\b/i;
+// Every cue must be linear-time: they run synchronously in handlePaste on every paste. The link cue bounds
+// its two spans with `[^\]]+`/`[^)]+` (not `.+`) — a double-`.+` catastrophically backtracks (ReDoS) on a
+// large bracket-heavy non-link paste and freezes the tab. Keep any new cue single-quantifier / negated-class.
const MARKDOWN_CUES = [
/^#{1,6}\s/m, // heading
/\*\*[^*]+\*\*/, // bold
- /\[.+\]\(.+\)/, // link
+ /\[[^\]]+\]\([^)]+\)/, // link
/^[-*+]\s/m, // bullet item
/^\d+\.\s/m, // ordered item
/^ {0,3}(?:```|~~~)/m, // fence