Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
fix(markdown-editor): protect pipe-less GFM table rows too (H1 gap)
Sergey Kozyrenko4d96cb3567db
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-content-integrity.test.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-content-integrity.test.tsindex 4ef94bbf..5b7e08c7 100644--- a/frontend/src/components/shared/markdown-editor/markdown-editor-content-integrity.test.ts+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-content-integrity.test.ts@@ -146,6 +146,9 @@ describe('generative content-integrity — atoms survive load↔serialize acrossfor (let i = 0; i < 120; i++) {const rowCount = 1 + Math.floor(rng() * 3);+ // GFM makes the outer pipe optional; generate BOTH styles so the pipe-less body-row path is exercised.+ const outerPipe = rng() < 0.5;+ const wrap = (cells: string) => (outerPipe ? `| ${cells} |` : cells);const rows: string[] = [];const sentinels: string[] = [];@@ -154,10 +157,10 @@ describe('generative content-integrity — atoms survive load↔serialize acrossconst sentinel = `${WORDS[Math.floor(rng() * WORDS.length)]}${row}`;sentinels.push(sentinel);- rows.push(`| \`${atom}\` | ${sentinel} |`);+ rows.push(wrap(`\`${atom}\` | ${sentinel}`));}- const doc = `| code | note |\n| --- | --- |\n${rows.join('\n')}`;+ const doc = `${wrap('code | note')}\n${wrap('--- | ---')}\n${rows.join('\n')}`;const out = roundTrip(doc);expect(roundTrip(out), `did not converge (i=${i}):\n${doc}\n-->\n${out}`).toBe(out);diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-table-pipes.test.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-table-pipes.test.tsindex 833ed71f..eb83c06f 100644--- a/frontend/src/components/shared/markdown-editor/markdown-editor-table-pipes.test.ts+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-table-pipes.test.ts@@ -78,3 +78,39 @@ describe('table cell with a piped code span — content survives load and converexpect(roundTrip(out)).toBe(out);});});++describe('pipe-less GFM tables (no outer pipe) — cells survive too', () => {+ it('protects a body row without a leading pipe', () => {+ expect(escapeTablePipes('A | B | C\n--- | --- | ---\n`git log | head` | notes | done')).toBe(+ 'A | B | C\n--- | --- | ---\n`git log \\| head` | notes | done',+ );+ });++ it('keeps the trailing cell of a no-leading-pipe table on round-trip', () => {+ const out = roundTrip('A | B | C\n--- | --- | ---\n`git log | head` | notes | done');++ expect(out).toContain('done');+ expect(out).toContain('`git log \\| head`');+ expect(roundTrip(out)).toBe(out);+ });++ it('protects a template action in a no-leading-pipe body row', () => {+ const out = roundTrip('Var | Out\n--- | ---\n{{.Host | lower}} | done');++ expect(out).toContain('done');+ expect(out).toContain('{{.Host \\| lower}}');+ });++ it('protects rows whether or not each has a leading pipe (mixed)', () => {+ const out = roundTrip('| A | B |\n| --- | --- |\n| `p | q` | one |\n`r | s` | two');++ expect(out).toContain('one');+ expect(out).toContain('two');+ });++ it('stops at a block boundary — a heading after the table is not escaped', () => {+ const src = 'A | B\n--- | ---\nr1 | r2\n# next `x | y` heading';++ expect(escapeTablePipes(src)).toBe(src);+ });+});diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-table-pipes.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-table-pipes.tsindex f0439045..b6126a2d 100644--- a/frontend/src/components/shared/markdown-editor/markdown-editor-table-pipes.ts+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-table-pipes.ts@@ -1,22 +1,40 @@// marked's GFM table tokenizer splits every row on raw `|` BEFORE inline tokenization, so a pipe inside a-// code span (`` `x | y` ``) or a Go-template action (`{{.X | upper}}`) in a body cell creates a phantom+// code span (`` `x | y` ``) or a Go-template action (`{{.X | upper}}`) in a cell creates a phantom// column and the trailing cells are silently DROPPED on load. The splitter does honor `\|` — and unescapes// it in the cell text — so pre-escaping those pipes before marked lexes protects the load side the same way// TunedTable's renderChildren escape protects the save side.//-// Scope is deliberately conservative — only rows that marked itself would treat as a table:+// Scope must match EXACTLY the rows marked itself treats as the table — no more, no less:// • the header/delimiter pair must already parse as a table (matching cell counts, delimiter has |/:) —-// escaping pipes in a NON-table line would surface literal `\|` (and could even turn a setext heading-// into a table by changing the header's cell count);-// • only BODY rows starting with `|` are transformed (header cell counts are structural; a body row is-// truncated/padded to the header width, so protecting its pipes only ever preserves more content);+// escaping pipes in a NON-table line would surface a literal `\|` (the escape tokenizer is neutralised,+// so `\|` outside a real table row does NOT unescape) and could even turn a setext heading into a table;+// • the leading/trailing pipe is OPTIONAL in GFM, so the header row AND every body row are transformed+// (marked's own gfmTable body capture — `(?!blank|hr|heading|blockquote|code|fences|list).*` — has no+// leading-pipe requirement; gating on a leading `|` dropped cells for the common no-outer-pipe style);+// • a table's rows run until a blank line or the start of another block (mirrored by ENDS_TABLE_BODY);// • fenced code blocks are never touched.+// Not covered: an HTML-block line (a standard block tag) immediately following a table with no blank line —+// marked would end the table there; we do not replicate its HTML-block interrupt (vanishingly rare in this+// content, and our html tokenizers render such lines as literal text anyway).const FENCE_LINE = /^ {0,3}(```|~~~)/;const TABLE_DELIMITER_LINE = /^ {0,3}\|? *:?-+:? *(?:\| *:?-+:? *)*\|? *$/;-const BODY_ROW_LINE = /^ {0,3}\|/;const TEMPLATE_ACTION = /\{\{[^{}]*\}\}/g;+// A table's body ends at a blank line or the first line that starts a different block — the same interrupts+// marked's gfmTable body-row negative lookahead lists (heading, blockquote, fences, list, hr, indented code).+const ENDS_TABLE_BODY = [+ /^[ \t]*$/,+ FENCE_LINE,+ /^ {0,3}#{1,6}(?: |\t|$)/,+ /^ {0,3}>/,+ /^ {0,3}(?:[*+-]|1[.)])[ \t]/,+ /^ {0,3}(?:(?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})$/,+ /^(?: {4}| {0,3}\t)/,+];++const endsTableBody = (line: string): boolean => ENDS_TABLE_BODY.some((rule) => rule.test(line));+const isEscapedAt = (text: string, offset: number): boolean => {let isEscaped = false;let index = offset;@@ -115,6 +133,15 @@ export const escapeTablePipes = (markdown: string): string => {let openFence: null | string = null;let isChanged = false;+ const escapeRow = (row: number): void => {+ const escaped = escapeRowPipes(lines[row]!);++ if (escaped !== lines[row]) {+ lines[row] = escaped;+ isChanged = true;+ }+ };+for (let index = 0; index < lines.length; index++) {const line = lines[index]!;const fence = FENCE_LINE.exec(line);@@ -139,13 +166,12 @@ export const escapeTablePipes = (markdown: string): string => {continue;}- for (let row = index + 2; row < lines.length && BODY_ROW_LINE.test(lines[row]!); row++) {- const escaped = escapeRowPipes(lines[row]!);+ // Header + every body row up to the block boundary; the delimiter row (index + 1) holds no cell+ // content. escapeRowPipes leaves structural pipes alone, so escaping the header can't skew its cell count.+ escapeRow(index);- if (escaped !== lines[row]) {- lines[row] = escaped;- isChanged = true;- }+ for (let row = index + 2; row < lines.length && !endsTableBody(lines[row]!); row++) {+ escapeRow(row);}}