From 030a54ffa6050c2e06cd9e3929cd8596dfcd73cd Mon Sep 17 00:00:00 2001 From: Arjun Krishna Date: Thu, 12 Nov 2026 19:03:42 +0530 Subject: [PATCH] fix(widgets): escape iot-chart series names ApexCharts writes series names into its tooltip with innerHTML, and the chart passed member-editable series labels (or device-chosen variable keys) straight through. A label containing markup became stored XSS for anyone hovering the chart, including owners and public share viewers. Names are now HTML-escaped before they reach ApexCharts. --- shared/widgets/iot-chart/widget.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/shared/widgets/iot-chart/widget.ts b/shared/widgets/iot-chart/widget.ts index 0bdd396..acfd959 100644 --- a/shared/widgets/iot-chart/widget.ts +++ b/shared/widgets/iot-chart/widget.ts @@ -264,7 +264,8 @@ export class IotChartElement extends HTMLElement { type === 'stepline' ? 'stepline' : 'smooth'; const seriesData = this.#series.map((s, i) => ({ - name: s.label ?? s.key, + // ApexCharts writes series names into the tooltip as HTML. + name: escapeHtml(s.label ?? s.key), color: s.color ?? PALETTE[i % PALETTE.length]!, data: s.points.map((p) => ({ x: p.ts * 1000, y: p.value })), })); @@ -386,3 +387,7 @@ function formatNumber(v: number): string { function isDark(): boolean { return typeof document !== 'undefined' && document.documentElement.classList.contains('dark'); } + +function escapeHtml(s: string): string { + return String(s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c] ?? c); +} -- knotmirror 0.0.1