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
feat(markdown-editor): decode named HTML entities outside code instead of freezing them
Sergey Kozyrenkoe4f80badd4bb
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 1da12c70..532c1584 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@@ -13,8 +13,9 @@ const mulberry32 = (seed: number) => () => {};// Content atoms that MUST survive load→serialize verbatim: identifiers/dunders, Go-template variables,-// xml-like tags, regex/path backslashes, HTML entities, C++. Whitespace/formatting may reflow; these-// bytes may not disappear or mutate.+// xml-like tags, regex/path backslashes, numeric HTML entities + a bare `&`, C++. Whitespace/formatting may+// reflow; these bytes may not disappear or mutate. (Named entities like `<` decode to `<` by design —+// see markdown-editor-marked.ts — so they are NOT survive-verbatim atoms.)const ATOMS = ['__init__','__call__',@@ -32,9 +33,9 @@ const ATOMS = ['regex \\.php files','glob \\* and \\?','escaped \\[ \\| \\+ here',- '<script>',+ '(paren)','AT&T',- 'x & y',+ '2>&1 redirect','C++ then C++','~10% left',];diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.test.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.test.tsindex e6b5a6e1..3717c7aa 100644--- a/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.test.ts+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.test.ts@@ -109,16 +109,27 @@ describe('backslash before punctuation survives — escape tokenizer neutralized});});-describe('HTML entities stay literal — decode neutralized (a pentest doc teaching <script> keeps its source)', () => {+describe('named HTML entities decode outside code; numeric refs, bare & and raw <tags> survive', () => {it.each([- 'encode <script> as text',- 'ampersand AT&T and a & b',- 'quote "value" and > alone and < too',+ ['encode <script> as text', 'encode <script> as text'],+ ['ampersand AT&T and a & b', 'ampersand AT&T and a & b'],+ ['quote "value" and > alone and < too', 'quote "value" and > alone and < too'],+ ])('decodes %s to its characters', (src, expected) => {+ expect(roundTrip(src)).toBe(expected);+ });++ it.each([+ 'numeric { and ( and % stay', // numeric refs are not decoded+ 'bare AT&T and a & b and 2>&1 survive', // a lone & is left literal])('keeps %s byte-identical', (s) => {expect(roundTrip(s)).toBe(s);});- it('literal <tags> (no entity) still stay literal, never entity-encoded', () => {+ it('entities inside inline code are preserved (code content is not decoded)', () => {+ expect(roundTrip('`<script>`')).toBe('`<script>`');+ });++ it('literal <tags> (raw, no entity) still stay literal, never entity-encoded', () => {expect(roundTrip('use <input> and <container_environment> here')).toBe('use <input> and <container_environment> here',);diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-marked.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-marked.tsindex 1a21c9cb..232c7d9a 100644--- a/frontend/src/components/shared/markdown-editor/markdown-editor-marked.ts+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-marked.ts@@ -14,24 +14,6 @@ const createFaithfulMarked = () => {const instance = new Marked();instance.use({- extensions: [- // @tiptap/markdown runs decodeHtmlEntities (`<`→`<`, `&`→`&`, `>`→`>`, `"`→`"`) on- // every text token during parse — a module-scope call its `.lexer()`/`.inlineTokens()` path never- // routes through marked's walkTokens/hooks, so those can't intercept it. Emit each literal `&` as- // its own text token pre-encoded to `&`; the decode then nets back to the original byte- // (`&`→`&`), leaving a source `<`/`&quot;` intact instead of collapsing it to `<`/`"`.- {- level: 'inline',- name: 'literalAmpersand',- start: (src: string) => {- const index = src.indexOf('&');-- return index < 0 ? undefined : index;- },- tokenizer: (src: string) =>- src[0] === '&' ? { raw: '&', text: '&', type: 'text' as const } : undefined,- },- ],tokenizer: {// These marked tokenizers auto-convert literal text into markup, mangling Go-template / pentest// prose on round-trip. Returning `undefined` forces the char to stay literal text; `false` defers@@ -43,6 +25,10 @@ const createFaithfulMarked = () => {// • html/tag — keep `<xml-like>` tags literal (marked swallows real-HTML-element names)// NB: autolink/url are intentionally NOT neutralised — a bare `https://…`, `<url>` or email is// meant to become a link (see markdown-editor-extensions.ts link config, kept symmetric with typing).+ // NB: named HTML entities (`< > & "`) are LEFT to marked's decoder — a bare-prose+ // `<` decodes to `<` (fixes HTML-encoding artifacts from ingestion). Numeric refs (`{`) and+ // anything inside code are untouched; a bare `&` survives as `&`. Don't re-add a literalAmpersand+ // token to "preserve" `<` — that re-freezes the artifacts.del: (src: string) => (/^~~(?!~)/.test(src) ? false : undefined),emStrong: (src: string) => (/^_/.test(src) ? undefined : false),escape: () => undefined,@@ -57,10 +43,10 @@ const createFaithfulMarked = () => {// The serialize-side counterpart to createFaithfulMarked. @tiptap/markdown's MarkdownManager// .encodeTextForMarkdown HTML-entity-encodes text (`<` → `<`) and backslash-escapes ``` ` * _ [ ] ~ \ ```.-// Both are wrong here: the load side neutralises marked's escape/html/tag tokenizers, so a `\`-escape or-// `<`-entity is NEVER decoded on parse — anything we encode now resurfaces as a literal backslash / entity-// on the next load, the exact corruption this editor avoids. Serialization is hard-coded in the manager (no-// per-extension hook), so replace that one method with identity, keeping load and save byte-symmetric.+// Both are wrong here: the load side keeps `\`+punct literal (escape tokenizer off), so re-escaping on save+// would double every backslash; and named HTML entities are DECODED on load (`<`→`<`), so re-encoding+// would freeze them back into `<`. Serialization is hard-coded in the manager (no per-extension hook), so+// replace that one method with identity — save emits exactly the text the doc holds.type ManagerWithEncode = { encodeTextForMarkdown: (text: string) => string };const FaithfulMarkdownText = Extension.create({