diff --git a/lib/__tests__/email-sanitization.test.ts b/lib/__tests__/email-sanitization.test.ts index 910d99d1..300591b1 100644 --- a/lib/__tests__/email-sanitization.test.ts +++ b/lib/__tests__/email-sanitization.test.ts @@ -14,6 +14,7 @@ import { decodeCssEscapes, styleHasExternalUrl, stripExternalCssUrls, + stripExternalStyleSheetCss, blockExternalResourcesOnNode, TRANSPARENT_BLOCKED_PIXEL, } from '../email-sanitization'; @@ -396,6 +397,42 @@ describe('email-sanitization', () => { }); }); + describe('stripExternalStyleSheetCss (', + ).body.firstElementChild!; + expect(blockExternalResourcesOnNode(style)).toBe(true); + expect(style.textContent).toBe('#x{background:url()}'); + }); + }); + describe('blockExternalResourcesOnNode (anti-tracking vectors)', () => { function el(html: string): Element { return parseHtmlSafely(`${html}`).body.firstElementChild!; diff --git a/lib/email-sanitization.ts b/lib/email-sanitization.ts index 69afdc3d..81a8f5a9 100644 --- a/lib/email-sanitization.ts +++ b/lib/email-sanitization.ts @@ -243,6 +243,43 @@ export function stripExternalCssUrls(style: string): string { ); } +/** + * Neutralise external references in a full stylesheet (a kept `