import { test } from '@japa/runner' import { sanitizePayload, sanitizeRichText, sanitizeUrl, } from '#base_modules/WebManager/services/content_sanitizer' test.group('Web Manager content sanitizer', () => { test('rich text keeps allowed markup and drops event handlers', ({ assert }) => { assert.equal( sanitizeRichText('
Hi there
'), 'Hi there
' ) }) test('rich text drops dangerous subtrees entirely', ({ assert }) => { assert.equal( sanitizeRichText('beforeafter'), 'beforeafter' ) }) test('rich text rejects unsafe link schemes and normalizes rel', ({ assert }) => { assert.equal( sanitizeRichText('x'), 'x' ) assert.equal( sanitizeRichText('x'), 'x' ) }) test('url fields allow relative and https urls, reject script schemes', ({ assert }) => { assert.equal(sanitizeUrl('/en/about'), '/en/about') assert.equal(sanitizeUrl('https://example.com/?a=1&b=2'), 'https://example.com/?a=1&b=2') assert.equal(sanitizeUrl('mailto:hi@example.com'), 'mailto:hi@example.com') assert.equal(sanitizeUrl('javascript:alert(1)'), '') assert.equal(sanitizeUrl(' jav\tascript:alert(1)'), '') }) test('payload pass applies the url policy to known url keys only', ({ assert }) => { assert.deepEqual( sanitizePayload({ title: 'Hello', externalUrl: 'javascript:alert(1)', items: [{ url: 'https://example.com/?a=1&b=2' }], }), { title: 'Hello', externalUrl: '', items: [{ url: 'https://example.com/?a=1&b=2' }], } ) }) })