From 548d45dec7553aa3a7d2dd80f55fe4f5df35a69c Mon Sep 17 00:00:00 2001 From: Lukas Spirig Date: Tue, 21 Nov 2023 08:19:43 +0100 Subject: [PATCH] fix(sbb-logo,sbb-signet): solve SSR issue with text assignment (#2208) Previous attempts to fix SSR failed due to various reasons. Now we just use property assignment with `.textContent`, which forces any text given to be interpreted as text. This avoid exploitation and simplifies the code. --- src/components/core/dom/index.ts | 1 - src/components/core/dom/strip-html.ts | 7 ------- src/components/logo/logo.ts | 8 +------- src/components/signet/signet.ts | 8 +------- 4 files changed, 2 insertions(+), 22 deletions(-) delete mode 100644 src/components/core/dom/strip-html.ts diff --git a/src/components/core/dom/index.ts b/src/components/core/dom/index.ts index c03874b880..1c21102b03 100644 --- a/src/components/core/dom/index.ts +++ b/src/components/core/dom/index.ts @@ -7,4 +7,3 @@ export * from './input-element'; export * from './is-valid-attribute'; export * from './platform'; export * from './scroll'; -export * from './strip-html'; diff --git a/src/components/core/dom/strip-html.ts b/src/components/core/dom/strip-html.ts deleted file mode 100644 index 7f301083c5..0000000000 --- a/src/components/core/dom/strip-html.ts +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Strips/removes HTML tags from a given value. - * @param value Value to strip HTML tags from. - */ -export function stripHTML(value: string): string { - return new DOMParser().parseFromString(value, 'text/html').body.textContent; -} diff --git a/src/components/logo/logo.ts b/src/components/logo/logo.ts index 1bb86061d0..0c80ba5b5a 100644 --- a/src/components/logo/logo.ts +++ b/src/components/logo/logo.ts @@ -1,8 +1,6 @@ import { CSSResultGroup, html, LitElement, nothing, TemplateResult } from 'lit'; import { customElement, property } from 'lit/decorators.js'; -import { unsafeSVG } from 'lit/directives/unsafe-svg.js'; -import { stripHTML } from '../core/dom'; import { SbbProtectiveRoom } from '../core/interfaces'; import style from './logo.scss?lit&inline'; @@ -25,15 +23,11 @@ export class SbbLogo extends LitElement { @property({ attribute: 'accessibility-label' }) public accessibilityLabel = 'Logo'; protected override render(): TemplateResult { - // unsafeSVG is required due to bug in Lit SSR: https://github.com/lit/lit/issues/4405 - // As unsafeSVG would allow any kind of content (including HTML) to be used, we - // remove any HTML content from the given accessibility label. - const accessibilityLabel = this.accessibilityLabel ? stripHTML(this.accessibilityLabel) : ''; return html`