Skip to content

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

fix(editor): keep literal HTML entities (< & > ") on load

Sergey Kozyrenko2e59e9e12269
diff --git a/frontend/src/components/shared/markdown-editor/editor-markdown.ts b/frontend/src/components/shared/markdown-editor/editor-markdown.ts
index c318e94a..326aa7d3 100644
--- a/frontend/src/components/shared/markdown-editor/editor-markdown.ts
+++ b/frontend/src/components/shared/markdown-editor/editor-markdown.ts
@@ -14,6 +14,24 @@ const createFaithfulMarked = () => {
const instance = new Marked();
instance.use({
+ extensions: [
+ // @tiptap/markdown runs decodeHtmlEntities (`&lt;`→`<`, `&amp;`→`&`, `&gt;`→`>`, `&quot;`→`"`) 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 `&amp;`; the decode then nets back to the original byte
+ // (`&amp;`→`&`), leaving a source `&lt;`/`&amp;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: '&amp;', type: 'text' as const } : undefined,
+ },
+ ],
tokenizer: {
// These marked tokenizers auto-convert literal text into markup a serialize-side escape can't undo,
// mangling Go-template / pentest prose on round-trip. Neutralise the lossy cases, keep what the
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.ts
index 786a7cd2..e52f7f87 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
@@ -105,6 +105,22 @@ describe('literal backslashes survive — no doubling (regex classes, Windows pa
});
});
+describe('HTML entities stay literal — decode neutralized (a pentest doc teaching &lt;script&gt; keeps its source)', () => {
+ it.each([
+ 'encode &lt;script&gt; as text',
+ 'ampersand AT&T and a &amp; b',
+ 'quote &quot;value&quot; and &gt; alone and &lt; too',
+ ])('keeps %s byte-identical', (s) => {
+ expect(roundTrip(s)).toBe(s);
+ });
+
+ it('literal <tags> (no entity) still stay literal, never entity-encoded', () => {
+ expect(roundTrip('use <input> and <container_environment> here')).toBe(
+ 'use <input> and <container_environment> here',
+ );
+ });
+});
+
describe('Underline disabled — ++ never parses, C++/++flags prose survives', () => {
it.each(['C++ then C++ again', 'a ++ b ++ c', 'compile ++flags++ here'])(
'keeps %s byte-identical (no ++ collapse)',
@@ -257,7 +273,9 @@ describe('typing matches load — underscore emphasis + bare-URL autolink disabl
for (const ch of input) {
const { from } = view.state.selection;
- const handled = view.someProp('handleTextInput', (handler) => handler(view, from, from, ch));
+ const handled = view.someProp('handleTextInput', (handler) =>
+ handler(view, from, from, ch, () => view.state.tr),
+ );
if (!handled) {
view.dispatch(view.state.tr.insertText(ch));