/* XSS regression tests for the rendering helpers in app.js. Run: node static/app.test.js Covers the audit's confirmed vectors: custom repo id, lookup/parser/narrator errors, and model-generated narrator output. esc() and safeUrl() are pure and run under Node; sanitizeHtml() needs a DOM, so it is exercised only when one is present (browser / jsdom) and otherwise reported as skipped. */ const { esc, safeUrl, sanitizeHtml } = require("./app.js"); let pass = 0, fail = 0; function ok(cond, msg) { if (cond) { pass++; } else { fail++; console.error("FAIL:", msg); } } // The exact payload from the audit, entered as a custom Hugging Face model id. const PAYLOAD = ``; // 1. esc() neutralises the proven exploit (repo id path, error path, narrator). const e = esc(PAYLOAD); ok(!e.includes("<"), "esc removes '<'"); ok(!e.includes(">"), "esc removes '>'"); ok(!/onerror=/.test(e) || !e.includes('"'), "esc breaks the onerror attribute (quotes escaped)"); ok(e.includes("<img"), "esc encodes the tag as text"); // 2. esc handles the field types from the audit (all plain-text sinks). ok(esc(`">`).indexOf("")), "sanitizeHtml drops