import {test, expect} from '../../fixtures/test' // javascript: URIs as XSS vectors appear in more attributes than just href. // form action, input formaction, and button formaction can also execute JS. // TinyMCE strips form elements entirely, but tests document this to ensure // a refactor doesn't accidentally start passing these through. test.describe('javascript: URI in form-related attributes', () => { 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('form with javascript: action — form stripped or action removed', async ({page}) => { const content = await setAndGet( page, '

Form text

After form

', ) expect(content).not.toContain('javascript:alert') expect(content).toContain('After form') }) test('button with javascript: formaction — stripped', async ({page}) => { const content = await setAndGet( page, '

Safe text

', ) expect(content).not.toContain('javascript:') expect(content).toContain('Safe text') }) test('input with javascript: formaction — stripped', async ({page}) => { const content = await setAndGet( page, '

Content

', ) expect(content).not.toContain('javascript:') expect(content).toContain('Content') }) test('iframe with javascript: src — stripped', async ({page}) => { const content = await setAndGet( page, '

Before

After

', ) expect(content).not.toContain('javascript:alert') expect(content).toContain('Before') expect(content).toContain('After') }) test('img with javascript: src — stripped', async ({page}) => { const content = await setAndGet( page, '

xssSafe paragraph

', ) expect(content).not.toContain('javascript:alert') expect(content).toContain('Safe paragraph') }) test('blockquote cite with javascript: — blockquote text preserved', async ({page}) => { // TinyMCE preserves the cite attribute on blockquote even with javascript: value. // The text content must survive; the cite attribute is not an execution vector // (browsers do not execute javascript: in cite). Document actual behavior. const content = await setAndGet( page, '

Quote text

', ) expect(content).toContain('Quote text') expect(typeof content).toBe('string') }) })