import {test, expect} from '../../fixtures/test' // Verifies that setContent() (which backs the defaultContent prop) also runs // content through canvas-rce's sanitization pipeline. // A bypass here would let XSS into Canvas via the defaultContent prop. test.describe('setContent sanitization', () => { test.beforeEach(async ({page, rcePage}) => { await page.goto('/scenarios/basic') await rcePage.waitForEditor() }) async function setAndGet(page: any, html: string): Promise { return page.evaluate((content: string) => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent(content) // @ts-expect-error -- TinyMCE global return window.tinymce.activeEditor.getContent() }, html) } test('script tag in setContent is stripped', async ({page}) => { const content = await setAndGet(page, '

safe

') expect(content).not.toContain('') expect(content).not.toContain('alert("svg")') }) test('style attribute with expression in setContent is stripped', async ({page}) => { const content = await setAndGet( page, 'text', ) expect(content).not.toContain('expression(') expect(content).toContain('text') }) })