import {test, expect} from '../../fixtures/test' // Advanced XSS patterns beyond basic script tags. These test the sanitization // pipeline against real-world attack vectors that naive sanitizers miss. test.describe('advanced XSS sanitization', () => { test.beforeEach(async ({page, rcePage}) => { await page.goto('/scenarios/basic') await rcePage.waitForEditor() await rcePage.contentFrame().locator('body').click() }) async function insert(page: any, html: string): Promise { await page.evaluate((content: string) => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.insertContent(content) }, html) return page.evaluate(() => { // @ts-expect-error -- TinyMCE global return window.tinymce.activeEditor.getContent() }) } test('data: URI in img src is stripped', async ({page, rcePage}) => { // data: URIs in images can be used to exfiltrate data via load events const content = await insert(page, '') // Either the img is removed entirely, or the data: src is sanitized if (content.includes('') } }) test('SVG with embedded script is stripped or sanitized', async ({page, rcePage}) => { const content = await insert(page, '') expect(content).not.toContain('alert("svg-xss")') }) test('onload attribute on img is stripped', async ({page, rcePage}) => { const content = await insert(page, '') expect(content).not.toContain('onload') }) test('onerror attribute on img is stripped', async ({page, rcePage}) => { const content = await insert(page, '') expect(content).not.toContain('onerror') }) test('meta refresh redirect is stripped', async ({page, rcePage}) => { const content = await insert( page, '', ) expect(content).not.toContain('http-equiv') expect(content).not.toContain('javascript:') }) test('event handler on table cell is stripped', async ({page, rcePage}) => { const content = await insert(page, '
cell
') expect(content).not.toContain('onclick') expect(content).toContain('cell') }) test('style with expression (IE-style CSS injection) is sanitized', async ({page, rcePage}) => { const content = await insert(page, 'text') // expression() should be stripped from style attributes expect(content).not.toContain('expression(') }) test('base tag is stripped', async ({page, rcePage}) => { // A tag could redirect all relative URLs to an attacker domain const content = await insert(page, '') expect(content).not.toContain(' { // TinyMCE may preserve HTML comments as-is; what matters is no *active*