diff --git a/changelog.d/make-pdf-nul-cannot-revive-handlers.md b/changelog.d/make-pdf-nul-cannot-revive-handlers.md new file mode 100644 index 000000000..7b21bf770 --- /dev/null +++ b/changelog.d/make-pdf-nul-cannot-revive-handlers.md @@ -0,0 +1,4 @@ +--- +important: security +--- +**make-pdf no longer lets a NUL character hide an `onerror` handler, a `javascript:` link or a `", + "", + "", + ].join("\n"); + const html = render({ markdown: md }).bodyHtml; + expect(liveScript(html)).toEqual([]); + expect(html).not.toMatch(/`, + `alert(1)`, + `alert(1)`, + ``, + ``, + ]) { + const html = render({ markdown: `
\n${x}\n
\n` }).bodyHtml; + expect(html).not.toMatch(/<(?:script|iframe|object)\b/i); + expect(liveScript(html)).toEqual([]); + } + }); + + test("a javascript: value after leading spaces or with an encoded colon is neutralized", () => { + for (const a of [`href=" javascript:alert(1)"`, `href="\tjavascript:alert(1)"`, "href=javascript:alert(1)", `href="javascript:alert(1)"`, "href=javascript:alert(1)"]) { + const html = render({ markdown: `
\nj\n
\n` }).bodyHtml; + expect(liveScript(html)).toEqual([]); + expect(html).toContain(">j"); + } + }); + + test("an unquoted javascript: value is replaced without adding quotes", () => { + const out = sanitizeUntrustedHtml("j"); + expect(liveScript(out)).toEqual([]); + expect(out).not.toContain('"'); + }); +}); + // ─── print-css ────────────────────────────────────────────── describe("printCss", () => {