refactor: simplify demo media

This commit is contained in:
ajnart committed 2026-08-24 12:07:07 +02:00
1 parent d8eec36d98
commit 245a477965
10 files changed
+14 -98

No files matched your search

@@ -18,11 +18,8 @@ describe("iframe policy", () => {
expect(getSandboxFlags(permissions)).toContain("allow-modals");
});
it("accepts HTTP URLs and same-origin paths", () => {
it("accepts only HTTP protocols", () => {
expect(isSupportedProtocol("https://example.com")).toBe(true);
expect(isSupportedProtocol("/api/demo-assets/overview")).toBe(true);
expect(isSupportedProtocol("//evil.example")).toBe(false);
expect(isSupportedProtocol("/\\evil.example")).toBe(false);
expect(isSupportedProtocol("javascript:alert(1)")).toBe(false);
expect(isSupportedProtocol("not a url")).toBe(false);
});
+3 -5
View File
@@ -7,15 +7,13 @@ import { objectEntries } from "@homarr/common";
import { useI18n } from "@homarr/translation/client";
import type { WidgetComponentProps } from "../definition";
import { getSafeApplicationUrl } from "../common/application-url";
import classes from "./component.module.css";
import { getSafeIframeUrl } from "./safe-url";
export { getSafeIframeUrl } from "./safe-url";
export default function IFrameWidget({ options, isEditMode }: WidgetComponentProps<"iframe">) {
const t = useI18n("widget.iframe");
const { embedUrl, allowScrolling, ...permissions } = options;
const safeEmbedUrl = getSafeIframeUrl(embedUrl);
const safeEmbedUrl = getSafeApplicationUrl(embedUrl);
const allowedPermissions = getAllowedPermissions(permissions);
const sandboxFlags = getSandboxFlags(permissions);
@@ -47,7 +45,7 @@ export default function IFrameWidget({ options, isEditMode }: WidgetComponentPro
const supportedProtocols = ["http", "https"];
export const isSupportedProtocol = (url: string) => {
return getSafeIframeUrl(url) !== undefined;
return getSafeApplicationUrl(url) !== undefined;
};
const NoUrl = () => {
+2 -2
View File
@@ -1,8 +1,8 @@
import { IconBrowser, IconExternalLink } from "@tabler/icons-react";
import { createWidgetDefinition } from "../definition";
import { getSafeApplicationUrl } from "../common/application-url";
import { optionsBuilder } from "../options";
import { getSafeIframeUrl } from "./safe-url";
const createOptions = () =>
optionsBuilder.from((factory) => ({
@@ -23,7 +23,7 @@ export const { definition, componentLoader } = createWidgetDefinition("iframe",
supportsAdvancedFocus: false,
icon: IconBrowser,
contextActions: ({ options }) => {
const embedUrl = getSafeIframeUrl(options.embedUrl);
const embedUrl = getSafeApplicationUrl(options.embedUrl);
return embedUrl
? [
{
-10
View File
@@ -1,10 +0,0 @@
import { getSafeAppHref, getSafeApplicationUrl } from "@homarr/common";
export const getSafeIframeUrl = (url: unknown) => {
const applicationUrl = getSafeApplicationUrl(url);
if (applicationUrl) return applicationUrl;
const relativeUrl = getSafeAppHref(url);
if (relativeUrl?.startsWith("/") && !relativeUrl.startsWith("//")) return relativeUrl;
return undefined;
};