mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-23 09:07:46 +02:00
Add markdown HTML security regressions
This commit is contained in:
1 parent
269bae3688
commit
89b94da25b
2 files changed
+39
No files matched your search
@@ -119,6 +119,20 @@ describe("MarkdownBody", () => {
|
||||
expect(html).not.toContain("javascript:");
|
||||
});
|
||||
|
||||
it("renders raw HTML tags as escaped text", () => {
|
||||
const html = renderMarkdown(
|
||||
'<script>fetch("/api/secrets")</script>\n<iframe src="https://example.com"></iframe>\n<p onclick="steal()">Plain text</p>',
|
||||
);
|
||||
|
||||
expect(html).not.toContain("<script>");
|
||||
expect(html).not.toContain("<iframe");
|
||||
expect(html).not.toContain("<p onclick");
|
||||
expect(html).not.toContain('onclick="steal()"');
|
||||
expect(html).toContain("<script>");
|
||||
expect(html).toContain("onclick="steal()"");
|
||||
expect(html).toContain("Plain text");
|
||||
});
|
||||
|
||||
it("uses soft-break styling by default", () => {
|
||||
const html = renderMarkdown("First line\nSecond line");
|
||||
|
||||
|
||||
@@ -299,6 +299,31 @@ describe("MarkdownEditor", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps scriptable pasted HTML inert in the rich editor", async () => {
|
||||
const root = createRoot(container);
|
||||
|
||||
await act(async () => {
|
||||
root.render(
|
||||
<MarkdownEditor
|
||||
value={'<script>fetch("/api/secrets")</script>\n<iframe src="https://example.com"></iframe>\n<p onclick="steal()">Plain text</p>'}
|
||||
onChange={() => {}}
|
||||
placeholder="Markdown body"
|
||||
/>,
|
||||
);
|
||||
});
|
||||
|
||||
await flush();
|
||||
expect(mdxEditorMockState.suppressHtmlProcessingValues).toContain(true);
|
||||
expect(container.querySelector("textarea")).toBeNull();
|
||||
expect(container.querySelector("script, iframe, p[onclick]")).toBeNull();
|
||||
expect(container.textContent).toContain('fetch("/api/secrets")');
|
||||
expect(container.textContent).toContain("Plain text");
|
||||
|
||||
await act(async () => {
|
||||
root.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to a raw textarea when the rich parser rejects the markdown", async () => {
|
||||
mdxEditorMockState.emitMountParseError = true;
|
||||
const handleChange = vi.fn();
|
||||
|
||||
Reference in new issue
Block a user