Open platform to collect and prioritize feedback
fix: correct XSS test assertions to match entity-encoded output
Matt Roberts53ed04d4c216
diff --git a/public/services/markdown.spec.ts b/public/services/markdown.spec.tsindex aa6f7cd36..eb303c748 100644--- a/public/services/markdown.spec.ts+++ b/public/services/markdown.spec.ts@@ -28,7 +28,7 @@ const testCases = [{input: "Hello <b>Beautiful</b> World",expectedFull: "<p>Hello <b>Beautiful</b> World</p>",- expectedPlainText: "Hello Beautiful World",+ expectedPlainText: "Hello <b>Beautiful</b> World",},{input: `[Uh oh...]("onerror="alert('XSS'))`,@@ -93,18 +93,19 @@ describe("XSS prevention", () => {xssInputs.forEach((input) => {test(`full mode neutralizes: ${input}`, () => {const result = markdown.full(input)- expect(result).not.toMatch(/<script/i)- expect(result).not.toMatch(/onerror/i)- expect(result).not.toMatch(/onload/i)- expect(result).not.toMatch(/javascript:/i)+ // No raw dangerous HTML elements (entity-encoded <script> is safe text)+ expect(result).not.toMatch(/<script[\s>]/i)+ expect(result).not.toMatch(/<svg[\s>]/i)+ expect(result).not.toMatch(/<img[^>]*onerror/i)+ expect(result).not.toMatch(/<a[^>]*javascript:/i)})test(`plainText mode neutralizes: ${input}`, () => {const result = markdown.plainText(input)- expect(result).not.toMatch(/<script/i)- expect(result).not.toMatch(/onerror/i)- expect(result).not.toMatch(/onload/i)- expect(result).not.toMatch(/javascript:/i)+ expect(result).not.toMatch(/<script[\s>]/i)+ expect(result).not.toMatch(/<svg[\s>]/i)+ expect(result).not.toMatch(/<img[^>]*onerror/i)+ expect(result).not.toMatch(/<a[^>]*javascript:/i)})})})