import {test, expect} from '../../fixtures/test'
// tags inside content body are injection vectors:
// - meta http-equiv="refresh" redirects users to malicious pages
// - meta http-equiv="set-cookie" injects cookies
// - meta charset changes page encoding (can bypass other filters)
// All meta tags must be stripped from the RCE content body.
test.describe(' tag 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', async ({page}) => {
const content = await setAndGet(
page,
'safe
',
)
expect(content).not.toContain(' encoding override is stripped', async ({page}) => {
const content = await setAndGet(page, 'content
')
expect(content).not.toContain(' is stripped from body', async ({page}) => {
const content = await setAndGet(
page,
'page text
',
)
expect(content).not.toContain(' is stripped', async ({page}) => {
const content = await setAndGet(
page,
'body
',
)
expect(content).not.toContain('set-cookie')
expect(content).not.toContain('hijacked')
expect(content).toContain('body')
})
test('content around tags is fully preserved', async ({page}) => {
const content = await setAndGet(
page,
'Title
Body text.
',
)
expect(content).toContain('Title')
expect(content).toContain('Body text')
expect(content).not.toContain('