fix(security): escape quotes in markdown renderer to block attribute-injection XSS — daily-sweep 2026-06-01

This commit is contained in:
Caelum Health Bot
2026-06-01 05:10:02 -04:00
parent fb9babecac
commit d1be1a34d5
2 changed files with 37 additions and 1 deletions
+6 -1
View File
@@ -5,7 +5,12 @@
// markdown.
function escape(s) {
return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
// Escape quotes too: inline() interpolates link hrefs/titles into double-quoted
// attributes, so an unescaped " in a [label](href) lets crafted markdown break
// out of the attribute and inject event handlers (DOM-XSS). Matters because the
// Lab renders LLM output through this — a prompt-injection surface.
return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
.replace(/"/g, '&quot;').replace(/'/g, '&#39;');
}
function inline(s) {
+31
View File
@@ -0,0 +1,31 @@
// Regression coverage for the tiny markdown renderer's HTML-attribute escaping.
// The renderer output is injected via v-html (Lab LLM output, Nox docs), so a
// crafted link must not break out of an attribute and inject an event handler.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { renderMarkdown } from '../src/views/nox/markdown.js';
test('link href cannot break out of the href attribute (DOM-XSS)', () => {
const html = renderMarkdown('[click](https://a" onmouseover="alert(1))');
// No raw-quote attribute injection: the only " must be the renderer's own
// attribute delimiters, never one closed by the payload mid-value.
assert.ok(!/onmouseover="/.test(html), 'injected event-handler attribute must not appear');
assert.ok(html.includes('&quot;'), 'the embedded quote must be escaped');
});
test('inert-link title cannot inject an attribute', () => {
const html = renderMarkdown('[x](foo" onmouseover="alert(1))');
assert.ok(!/onmouseover="/.test(html), 'injected event-handler attribute must not appear');
assert.ok(html.includes('&quot;'), 'the embedded quote must be escaped');
});
test('plain text with a quote renders the escaped entity', () => {
const html = renderMarkdown('she said "hi"');
assert.ok(html.includes('&quot;hi&quot;'));
});
test('a normal https link still renders as an anchor', () => {
const html = renderMarkdown('[docs](https://caelum.network/nox/docs)');
assert.ok(html.includes('href="https://caelum.network/nox/docs"'));
assert.ok(html.includes('>docs</a>'));
});