import { describe, expect, it } from "vitest"; import { renderIntroMarkdown } from "./markdown.js"; /** * TASK-0107 DoD — "XSS vectors stripped (sanitizer test list)". * * `renderIntroMarkdown` is the ONLY way a form's `config.intro` (an * OWNER-supplied, publicly rendered string) reaches the DOM. The contract * (see markdown.ts) is: HTML-escape the ENTIRE input first, then apply a * strict block grammar + an allow-list of inline transforms * (strong / em / http(s)-only links). So the ONLY HTML the function can emit * is the literal tags it inserts itself. This suite pins that contract. * * Two assertions per vector class: * 1. the DANGEROUS token never appears as a live tag/attribute in the * output (it is either escaped or dropped), AND * 2. the legitimate transforms the feature actually promises still work * (the sanitizer is not so aggressive it breaks the feature). */ const VECTORS = [ // classic script injection "", "", "", // event-handler injection on common elements "", "", "", "", // iframe / object embedding "", "", "", // javascript: URI in a link (both raw and markdown form) 'click', "[click](javascript:alert(1))", "[click](data:text/html,)", // null-byte / whitespace obfuscation "alert(1)", "alert(1)", "", // style / expression injection "
", "", // double-encode attempt (should just be escaped text) "<script>alert(1)</script>" ]; describe("renderIntroMarkdown — XSS sanitizer (TASK-0107 DoD)", () => { it("never emits a live