mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-02 19:45:54 +01:00
fix: iframes javascript content
This commit is contained in:
@@ -7,8 +7,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"modal": {
|
"modal": {
|
||||||
"text": "",
|
"text": "The widet crashed unexpectitly. Please read the documentation and fix any typos.",
|
||||||
"label": "Your error",
|
"label": "Occurred error",
|
||||||
"reportButton": "Report this error"
|
"reportButton": "Report this error on GitHub"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,20 @@ import { useTranslation } from 'next-i18next';
|
|||||||
import { defineWidget } from '../helper';
|
import { defineWidget } from '../helper';
|
||||||
import { IWidget } from '../widgets';
|
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({
|
const definition = defineWidget({
|
||||||
id: 'iframe',
|
id: 'iframe',
|
||||||
icon: IconBrowser,
|
icon: IconBrowser,
|
||||||
@@ -116,9 +130,8 @@ function IFrameTile({ widget }: IFrameTileProps) {
|
|||||||
return (
|
return (
|
||||||
<Container h="100%" w="100%" maw="initial" mah="initial" p={0}>
|
<Container h="100%" w="100%" maw="initial" mah="initial" p={0}>
|
||||||
<iframe
|
<iframe
|
||||||
sandbox="" // Disables js execution see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#sandbox
|
|
||||||
className={classes.iframe}
|
className={classes.iframe}
|
||||||
src={widget.properties.embedUrl}
|
src={sanitizeUrl(widget.properties.embedUrl)}
|
||||||
title="widget iframe"
|
title="widget iframe"
|
||||||
allow={allowedPermissions.join(' ')}
|
allow={allowedPermissions.join(' ')}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user