sanitization.spec.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { createRandomPage } from './utils'
  4. test('custom html should not spawn any dialogs', async ({ page, block }) => {
  5. page.on('dialog', async dialog => {
  6. expect(false).toBeTruthy()
  7. await dialog.dismiss()
  8. })
  9. await createRandomPage(page)
  10. await page.keyboard.type('<iframe src="javascript:confirm(1);" />', { delay: 5 })
  11. await block.enterNext()
  12. await page.keyboard.type('<button id="test-xss-button" onclick="confirm(1)">Click me!</button>', { delay: 5 })
  13. await block.enterNext()
  14. await page.keyboard.type('<details open id="test-xss-toggle" ontoggle="confirm(1)">test</details>', { delay: 5 })
  15. await block.enterNext()
  16. await page.click('#test-xss-toggle')
  17. await page.click('#test-xss-button')
  18. expect(true).toBeTruthy()
  19. })
  20. test('custom hiccup should not spawn any dialogs', async ({ page, block }) => {
  21. page.on('dialog', async dialog => {
  22. expect(false).toBeTruthy()
  23. await dialog.dismiss()
  24. })
  25. await createRandomPage(page)
  26. await page.keyboard.type('[:iframe {:src "javascript:confirm(1);"}]', { delay: 5 })
  27. await block.enterNext()
  28. expect(true).toBeTruthy()
  29. })
  30. test('"is" attribute should be allowed for plugin purposes', async ({ page, block }) => {
  31. await createRandomPage(page)
  32. await page.keyboard.type('[:div {:is "custom-element" :id "custom-element-id"}]', { delay: 5 })
  33. await block.enterNext()
  34. await expect(page.locator('#custom-element-id')).toHaveAttribute('is', 'custom-element');
  35. })