Skip to content

The open alternative to Salesforce, designed for AI.

Strip template elements from the HTML block preview (#23866)

Félix Malfait712e5ece7e7b
diff --git a/packages/twenty-front/src/modules/advanced-text-editor/utils/__tests__/sanitizeHtmlPreview.test.ts b/packages/twenty-front/src/modules/advanced-text-editor/utils/__tests__/sanitizeHtmlPreview.test.ts
index a9d53addc66..09ff81d6837 100644
--- a/packages/twenty-front/src/modules/advanced-text-editor/utils/__tests__/sanitizeHtmlPreview.test.ts
+++ b/packages/twenty-front/src/modules/advanced-text-editor/utils/__tests__/sanitizeHtmlPreview.test.ts
@@ -53,6 +53,19 @@ describe('sanitizeHtmlPreview', () => {
).toContain('data:image/png');
});
+ it('should remove templates instead of leaving their handlers unreachable', () => {
+ expect(
+ sanitizeHtmlPreview(
+ '<template><img src=x onerror="alert(1)"></template>',
+ ),
+ ).toBe('');
+ expect(
+ sanitizeHtmlPreview(
+ '<div><template><img src=x onerror="alert(1)"></template></div>',
+ ),
+ ).toBe('<div></div>');
+ });
+
it('should strip srcdoc and formaction attributes', () => {
expect(
sanitizeHtmlPreview('<div srcdoc="<script>x</script>">a</div>'),
diff --git a/packages/twenty-front/src/modules/advanced-text-editor/utils/sanitizeHtmlPreview.ts b/packages/twenty-front/src/modules/advanced-text-editor/utils/sanitizeHtmlPreview.ts
index 3638d769592..9501658c8d5 100644
--- a/packages/twenty-front/src/modules/advanced-text-editor/utils/sanitizeHtmlPreview.ts
+++ b/packages/twenty-front/src/modules/advanced-text-editor/utils/sanitizeHtmlPreview.ts
@@ -1,5 +1,5 @@
const BLOCKED_ELEMENT_SELECTOR =
- 'script, iframe, frame, object, embed, link, meta, base, style, svg, math';
+ 'script, iframe, frame, object, embed, link, meta, base, style, svg, math, template';
const URL_ATTRIBUTE_NAMES = ['href', 'src', 'xlink:href', 'action'];