From 85547277d1daf7065fffe60d516f4d5dd0b67878 Mon Sep 17 00:00:00 2001 From: Manuel <30572287+manuel-rw@users.noreply.github.com> Date: Sun, 8 Dec 2024 20:06:15 +0100 Subject: [PATCH 1/8] fix: iframes javascript content (#2218) --- package.json | 2 +- public/locales/en/widgets/error-boundary.json | 6 +++--- src/widgets/iframe/IFrameTile.tsx | 17 +++++++++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index cf60568f2ef..2c3c8cd96a5 100644 --- a/package.json +++ b/package.json @@ -244,4 +244,4 @@ ] } } -} \ No newline at end of file +} diff --git a/public/locales/en/widgets/error-boundary.json b/public/locales/en/widgets/error-boundary.json index 2087e254087..395176d0141 100644 --- a/public/locales/en/widgets/error-boundary.json +++ b/public/locales/en/widgets/error-boundary.json @@ -7,8 +7,8 @@ } }, "modal": { - "text": "", - "label": "Your error", - "reportButton": "Report this error" + "text": "The widet crashed unexpectitly. Please read the documentation and fix any typos.", + "label": "Occurred error", + "reportButton": "Report this error on GitHub" } } diff --git a/src/widgets/iframe/IFrameTile.tsx b/src/widgets/iframe/IFrameTile.tsx index ab3f1790d71..4c49af3b990 100644 --- a/src/widgets/iframe/IFrameTile.tsx +++ b/src/widgets/iframe/IFrameTile.tsx @@ -5,6 +5,20 @@ import { useTranslation } from 'next-i18next'; import { defineWidget } from '../helper'; import { IWidget } from '../widgets'; +function sanitizeUrl(url: string) { + let parsedUrl: URL; + try { + parsedUrl = new URL(url); + } catch (e) { + return 'about:blank'; + } + if (['http:', 'https:'].includes(parsedUrl.protocol)) { + return parsedUrl.href; + } else { + throw new Error(`Protocol '${parsedUrl.protocol}' is not supported. Use HTTP or HTTPS.`); + } +} + const definition = defineWidget({ id: 'iframe', icon: IconBrowser, @@ -116,9 +130,8 @@ function IFrameTile({ widget }: IFrameTileProps) { return (