diff --git a/lib/__tests__/email-sanitization.test.ts b/lib/__tests__/email-sanitization.test.ts index 4691b0e0..103d2dcf 100644 --- a/lib/__tests__/email-sanitization.test.ts +++ b/lib/__tests__/email-sanitization.test.ts @@ -6,6 +6,7 @@ import { parseHtmlSafely, hasRichFormatting, plainTextToSafeHtml, + sanitizePlainTextRenderedHtml, EMAIL_SANITIZE_CONFIG, EMAIL_IFRAME_SANITIZE_CONFIG, isExternalResourceUrl, @@ -580,4 +581,24 @@ describe('email-sanitization', () => { expect(result).toContain('javascript:alert(1)'); }); }); + + describe('sanitizePlainTextRenderedHtml', () => { + // This branch renders into the main document, not the sandboxed iframe, so + // an anchor that loses target="_blank" navigates the whole app away. + it('preserves target and rel on links emitted by plainTextToSafeHtml', () => { + const rendered = sanitizePlainTextRenderedHtml( + plainTextToSafeHtml('see https://github.com/honzup/webmail/pull/560'), + ); + expect(rendered).toContain('target="_blank"'); + expect(rendered).toContain('rel="noopener noreferrer"'); + }); + + it('still strips dangerous schemes and tags', () => { + const rendered = sanitizePlainTextRenderedHtml( + 'x', + ); + expect(rendered).not.toContain('javascript:'); + expect(rendered).not.toContain('