import {test, expect} from '../../fixtures/test' // Form elements (, , , ) inside course content // are a form injection vector — they can hijack Canvas form submissions or trick // students into entering credentials. TinyMCE should strip or neuter them. // This documents what canvas-rce actually allows through its filter. test.describe('form element 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(' is stripped or its value is not executable', async ({page}) => { const content = await setAndGet( page, 'Enter your info: ', ) // Input must not appear as a live form field that can be submitted // TinyMCE may strip or convert it — both are acceptable expect(content).not.toContain('name="username"') expect(content).toContain('Enter your info') }) test(' is stripped', async ({page}) => { const content = await setAndGet(page, '') expect(content).not.toContain('type="password"') expect(content).not.toContain('placeholder="Enter password"') }) test(' form element is stripped', async ({page}) => { const content = await setAndGet( page, 'Feedback:default text', ) // Either stripped or inert — textarea must not be a live form field if (content.includes(' dropdown is stripped', async ({page}) => { const content = await setAndGet( page, 'Option AOption B', ) expect(content).not.toContain(' wrapper element is stripped', async ({page}) => { const content = await setAndGet( page, 'Content inside form', ) expect(content).not.toContain(' is stripped', async ({page}) => { const content = await setAndGet( page, 'Visible', ) expect(content).not.toContain('csrf_token') expect(content).not.toContain('stolen') expect(content).toContain('Visible') }) test(' button is stripped or formaction removed', async ({page}) => { const content = await setAndGet( page, '', ) expect(content).not.toContain('formaction') expect(content).not.toContain('evil.example.com') }) })
Enter your info:
Feedback:
Content inside form
Visible