|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | import {secretToken} from '../../../src/internals/secrets';
|
8 |
| -import {HTML_TEST_VECTORS} from '../../testing/testvectors/html_test_vectors'; |
9 | 8 |
|
10 | 9 | import {
|
11 | 10 | CssSanitizationFn,
|
@@ -51,16 +50,46 @@ function sanitizeAssertUnchanged(table: SanitizerTable, html: string): string {
|
51 | 50 | .toString();
|
52 | 51 | }
|
53 | 52 |
|
54 |
| -describe('HtmlSanitizer', () => { |
55 |
| - describe('using test vectors', () => { |
56 |
| - for (const v of HTML_TEST_VECTORS) { |
57 |
| - it(`passes testVector[${v.name}]`, () => { |
58 |
| - const sanitized = sanitizeHtml(v.input).toString(); |
59 |
| - expect(v.acceptable).toContain(sanitized); |
60 |
| - }); |
61 |
| - } |
62 |
| - }); |
| 53 | +describe('sanitizeHtml', () => { |
| 54 | + interface TestCase { |
| 55 | + html: string; |
| 56 | + expected: string; |
| 57 | + } |
| 58 | + const testCases: TestCase[] = [ |
| 59 | + { |
| 60 | + html: '<a href="javascript:evil()"></a>', |
| 61 | + expected: '<a href="about:invalid#zClosurez"></a>', |
| 62 | + }, |
| 63 | + { |
| 64 | + html: 'ab<script>alert(1)</script>cd', |
| 65 | + expected: 'abcd', |
| 66 | + }, |
| 67 | + { |
| 68 | + html: 'ab<style>*{}</style>cd', |
| 69 | + expected: 'abcd', |
| 70 | + }, |
| 71 | + { |
| 72 | + html: '<iframe src="javascript:evil()"></iframe>', |
| 73 | + expected: '', |
| 74 | + }, |
| 75 | + { |
| 76 | + html: '<img src=1 onerror=alert(1)>', |
| 77 | + expected: '<img src="1" />', |
| 78 | + }, |
| 79 | + { |
| 80 | + html: '<select><style></select><script>alert(1)</script>', |
| 81 | + expected: '<select></select>', |
| 82 | + }, |
| 83 | + ]; |
| 84 | + for (const testCase of testCases) { |
| 85 | + it(`sanitizes ${JSON.stringify(testCase.html)} correctly`, () => { |
| 86 | + const sanitized = sanitizeHtml(testCase.html).toString(); |
| 87 | + expect(sanitized).toEqual(testCase.expected); |
| 88 | + }); |
| 89 | + } |
| 90 | +}); |
63 | 91 |
|
| 92 | +describe('HtmlSanitizer', () => { |
64 | 93 | it('drops unknown elements', () => {
|
65 | 94 | const emptyTable = new SanitizerTable(
|
66 | 95 | new Set(),
|
|
0 commit comments