Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

fix(apps): remove app URL validation (#7238)

Thomasacbabd92167a
diff --git a/apps/docs/public/api/open-api-schema.json b/apps/docs/public/api/open-api-schema.json
index 5d14ebccc..809a7db7c 100644
--- a/apps/docs/public/api/open-api-schema.json
+++ b/apps/docs/public/api/open-api-schema.json
@@ -371,15 +371,7 @@
"href": {
"anyOf": [
{
- "anyOf": [
- {
- "type": "string"
- },
- {
- "type": "string",
- "const": ""
- }
- ]
+ "type": "string"
},
{
"type": "null"
@@ -986,15 +978,7 @@
"href": {
"anyOf": [
{
- "anyOf": [
- {
- "type": "string"
- },
- {
- "type": "string",
- "const": ""
- }
- ]
+ "type": "string"
},
{
"type": "null"
diff --git a/apps/nextjs/src/app/[locale]/manage/apps/page.tsx b/apps/nextjs/src/app/[locale]/manage/apps/page.tsx
index e9f973abc..9aa125bcf 100644
--- a/apps/nextjs/src/app/[locale]/manage/apps/page.tsx
+++ b/apps/nextjs/src/app/[locale]/manage/apps/page.tsx
@@ -7,7 +7,6 @@ import { z } from "zod/v4";
import type { RouterOutputs } from "@homarr/api";
import { api } from "@homarr/api/server";
import { auth } from "@homarr/auth/next";
-import { getSafeAppHref } from "@homarr/common";
import type { inferSearchParamsFromSchema } from "@homarr/common/types";
import { getI18n } from "@homarr/translation/server";
import { Link, SearchInput, TablePagination } from "@homarr/ui";
@@ -136,7 +135,6 @@ interface AppItemProps {
const AppItem = ({ app, canDelete, editLabel }: AppItemProps) => {
const descriptionLines = app.description?.split("\n");
- const safeHref = getSafeAppHref(app.href);
return (
<ManageCollectionItem
@@ -159,9 +157,9 @@ const AppItem = ({ app, canDelete, editLabel }: AppItemProps) => {
) : undefined
}
metadata={
- safeHref ? (
+ app.href ? (
<Anchor
- href={safeHref}
+ href={app.href}
target="_blank"
rel="noreferrer"
lineClamp={1}
diff --git a/apps/nextjs/src/components/board/board-apps-spotlight-registrar.tsx b/apps/nextjs/src/components/board/board-apps-spotlight-registrar.tsx
index 721301860..7d1431fed 100644
--- a/apps/nextjs/src/components/board/board-apps-spotlight-registrar.tsx
+++ b/apps/nextjs/src/components/board/board-apps-spotlight-registrar.tsx
@@ -4,7 +4,6 @@ import { useEffect, useMemo, useState } from "react";
import { clientApi } from "@homarr/api/client";
import { useRequiredBoard } from "@homarr/boards/context";
-import { getSafeAppHref } from "@homarr/common";
import type { ContextSpecificItem } from "@homarr/spotlight";
import { useRegisterSpotlightContextResults } from "@homarr/spotlight";
import { hasPendingSpotlightOpen, spotlightOpenEvent } from "@homarr/spotlight/open";
@@ -42,7 +41,7 @@ export const BoardAppsSpotlightRegistrar = () => {
const apps = appQueries.flatMap((query) => query.data ?? []);
const spotlightItems = useMemo<ContextSpecificItem[]>(() => {
return apps.flatMap((app) => {
- const href = getSafeAppHref(app.href);
+ const href = app.href;
if (!href) return [];
return [
diff --git a/apps/nextjs/src/components/board/sections/use-open-section-apps.ts b/apps/nextjs/src/components/board/sections/use-open-section-apps.ts
index 44292d580..6e186f475 100644
--- a/apps/nextjs/src/components/board/sections/use-open-section-apps.ts
+++ b/apps/nextjs/src/components/board/sections/use-open-section-apps.ts
@@ -2,7 +2,6 @@ import { useCallback, useMemo } from "react";
import { clientApi } from "@homarr/api/client";
import { useCurrentLayout, useRequiredBoard } from "@homarr/boards/context";
-import { getSafeAppHref } from "@homarr/common";
import { useConfirmModal } from "@homarr/modals";
import { useI18n } from "@homarr/translation/client";
@@ -94,7 +93,7 @@ export const useOpenSectionApps = (sectionId: string, enabled: boolean) => {
});
const open = useCallback(() => {
- const appUrls = apps.map((app) => getSafeAppHref(app.href)).filter((href) => href !== undefined);
+ const appUrls = apps.map((app) => app.href).filter((href): href is string => Boolean(href));
for (const href of appUrls) {
const openedWindow = window.open(href);
diff --git a/packages/common/src/url.ts b/packages/common/src/url.ts
index 271d380e0..079de8418 100644
--- a/packages/common/src/url.ts
+++ b/packages/common/src/url.ts
@@ -75,22 +75,6 @@ export const getSafeApplicationUrl = (value: unknown, options: SafeApplicationUr
}
};
-/** Returns a safe user-configured app link, including same-origin paths and custom URI schemes. */
-export const getSafeAppHref = (value: unknown): string | undefined => {
- if (typeof value !== "string" || value.trim() === "") return undefined;
-
- const href = value.trim();
- if (/^(?:javascript|data|vbscript|file|blob):/i.test(href)) return undefined;
-
- try {
- const url = new URL(href);
- if (url.username !== "" || url.password !== "") return undefined;
- return url.toString();
- } catch {
- return /^(?:[#?]|\/(?![\\/])|\.{1,2}\/)/.test(href) ? href : undefined;
- }
-};
-
const parseHttpUrl = (value: unknown, baseUrl?: string): URL | undefined => {
if (typeof value !== "string") return undefined;
const url = new URL(value, baseUrl);
diff --git a/packages/spotlight/src/components/actions/items/children-action-item.tsx b/packages/spotlight/src/components/actions/items/children-action-item.tsx
index 6d3e28a6b..58a383e1c 100644
--- a/packages/spotlight/src/components/actions/items/children-action-item.tsx
+++ b/packages/spotlight/src/components/actions/items/children-action-item.tsx
@@ -1,6 +1,6 @@
import { Spotlight } from "@mantine/spotlight";
-import { getSafeAppHref, SAFE_NEW_TAB_REL } from "@homarr/common";
+import { SAFE_NEW_TAB_REL } from "@homarr/common";
import { Link } from "@homarr/ui";
import type { inferSearchInteractionOptions } from "../../../lib/interaction";
@@ -16,13 +16,12 @@ interface ChildrenActionItemProps {
export const ChildrenActionItem = ({ childrenOptions, action, query, setChildrenOptions }: ChildrenActionItemProps) => {
const interaction = action.useInteraction(childrenOptions.option, query);
- const safeHref = interaction.type === "link" ? getSafeAppHref(interaction.href) : undefined;
const renderRoot =
- interaction.type === "link" && safeHref
+ interaction.type === "link" && interaction.href
? (props: Record<string, unknown>) => {
return (
<Link
- href={safeHref}
+ href={interaction.href}
target={interaction.newTab ? "_blank" : undefined}
rel={interaction.newTab ? SAFE_NEW_TAB_REL : undefined}
{...props}
diff --git a/packages/spotlight/src/components/actions/items/group-action-item.tsx b/packages/spotlight/src/components/actions/items/group-action-item.tsx
index f0874172a..ea871d955 100644
--- a/packages/spotlight/src/components/actions/items/group-action-item.tsx
+++ b/packages/spotlight/src/components/actions/items/group-action-item.tsx
@@ -1,6 +1,6 @@
import { Spotlight } from "@mantine/spotlight";
-import { getSafeAppHref, SAFE_NEW_TAB_REL } from "@homarr/common";
+import { SAFE_NEW_TAB_REL } from "@homarr/common";
import { Link } from "@homarr/ui";
import type { SearchGroup } from "../../../lib/group";
@@ -32,13 +32,12 @@ export const SpotlightGroupActionItem = <TOption extends Record<string, unknown>
const { key: _reactKey, ...optionProps } = option as unknown as { key?: unknown } & Record<string, unknown>;
- const safeHref = interaction.type === "link" ? getSafeAppHref(interaction.href) : undefined;
const renderRoot =
- interaction.type === "link" && safeHref && !unavailable
+ interaction.type === "link" && interaction.href && !unavailable
? (props: Record<string, unknown>) => {
return (
<Link
- href={safeHref}
+ href={interaction.href}
target={interaction.newTab ? "_blank" : undefined}
rel={interaction.newTab ? SAFE_NEW_TAB_REL : undefined}
{...props}
diff --git a/packages/validation/src/app.ts b/packages/validation/src/app.ts
index dfc7652a7..fba3bd481 100644
--- a/packages/validation/src/app.ts
+++ b/packages/validation/src/app.ts
@@ -2,9 +2,6 @@ import { z } from "zod/v4";
export const appHrefSchema = z
.string()
- .trim()
- .refine((val) => !/^javascript:/i.test(val), "JavaScript URIs are not permitted")
- .or(z.literal(""))
.transform((value) => (value.length === 0 ? null : value))
.nullable();
diff --git a/packages/widgets/src/app/component.tsx b/packages/widgets/src/app/component.tsx
index cb249e14e..2d83b4319 100644
--- a/packages/widgets/src/app/component.tsx
+++ b/packages/widgets/src/app/component.tsx
@@ -13,7 +13,7 @@ import { useI18n } from "@homarr/translation/client";
import { MaskedOrNormalImage } from "@homarr/ui";
import { WidgetEmptyState } from "../common/empty-state";
-import { getSafeAppHref, SAFE_NEW_TAB_REL } from "../common/application-url";
+import { SAFE_NEW_TAB_REL } from "../common/application-url";
import { getUsableWidgetQueryData, isInitialWidgetQueryPending } from "../common/query-state";
import { WidgetQueryLoadingState } from "../common/query-state-indicator";
import type { WidgetComponentProps } from "../definition";
@@ -33,7 +33,7 @@ export default function AppWidget({
const board = useRequiredBoard();
const appQuery = clientApi.app.byId.useQuery({ id: options.appId }, { enabled: Boolean(options.appId) });
const app = getUsableWidgetQueryData(appQuery);
- const href = getSafeAppHref(app?.href);
+ const href = app?.href ?? undefined;
if (!options.appId) return <WidgetEmptyState />;
if (isInitialWidgetQueryPending(appQuery)) return <WidgetQueryLoadingState />;
diff --git a/packages/widgets/src/bookmarks/bookmarks-widget.tsx b/packages/widgets/src/bookmarks/bookmarks-widget.tsx
index 03f6cdaa6..1f0270762 100644
--- a/packages/widgets/src/bookmarks/bookmarks-widget.tsx
+++ b/packages/widgets/src/bookmarks/bookmarks-widget.tsx
@@ -27,7 +27,7 @@ import { useRegisterSpotlightContextResults } from "@homarr/spotlight";
import { useI18n } from "@homarr/translation/client";
import { iconSizes, zoomCompensatedSize } from "@homarr/ui";
-import { getSafeAppHref, SAFE_NEW_TAB_REL } from "../common/application-url";
+import { SAFE_NEW_TAB_REL } from "../common/application-url";
import { getUsableWidgetQueryData, isInitialWidgetQueryPending } from "../common/query-state";
import { WidgetQueryLoadingState } from "../common/query-state-indicator";
import type { WidgetComponentProps } from "../definition";
@@ -103,7 +103,7 @@ export default function BookmarksWidget({
useRegisterSpotlightContextResults(
`bookmark-${itemId}`,
data.flatMap((bookmark) => {
- const href = getSafeAppHref(bookmark.href);
+ const href = bookmark.href;
if (!href) return [];
return [
@@ -321,7 +321,7 @@ const BookmarkCard = ({
}: BookmarkCardProps) => {
const [active, setActive] = useState(false);
const reduceMotion = useReducedMotion();
- const href = getSafeAppHref(bookmark.href);
+ const href = bookmark.href ?? undefined;
const hostname = bookmark.href ? getBookmarkHostname(bookmark.href) : undefined;
const iconUrl = bookmark.iconUrl ?? getBookmarkFaviconUrl(bookmark.href);
const iconOnly = orientation === "icon" || (!showTitle && !showHostname);
diff --git a/packages/widgets/src/common/application-url.spec.ts b/packages/widgets/src/common/application-url.spec.ts
index a990c53b6..7866461bc 100644
--- a/packages/widgets/src/common/application-url.spec.ts
+++ b/packages/widgets/src/common/application-url.spec.ts
@@ -1,6 +1,6 @@
import { describe, expect, test } from "vitest";
-import { getSafeApplicationUrl, getSafeAppHref } from "./application-url";
+import { getSafeApplicationUrl } from "./application-url";
describe("getSafeApplicationUrl", () => {
test.each(["javascript:alert(1)", "data:text/html,test", "not a URL", "/relative", "./relative"])(
@@ -28,19 +28,3 @@ describe("getSafeApplicationUrl", () => {
expect(getSafeApplicationUrl(value)).toBeUndefined();
});
});
-
-describe("getSafeAppHref", () => {
- test.each(["#section", "/boards/home", "./relative", "vscode://file/example.ts", "https://example.com/path"])(
- "allows configured app link %s",
- (value) => expect(getSafeAppHref(value)).toBe(value),
- );
-
- test.each([
- "javascript:alert(1)",
- "data:text/html,test",
- "file:///etc/passwd",
- "//example.com/path",
- "not a URL",
- "https://user:[email protected]/path",
- ])("rejects unsafe app link %s", (value) => expect(getSafeAppHref(value)).toBeUndefined());
-});
diff --git a/packages/widgets/src/common/application-url.ts b/packages/widgets/src/common/application-url.ts
index b43d335f3..cfbef8abc 100644
--- a/packages/widgets/src/common/application-url.ts
+++ b/packages/widgets/src/common/application-url.ts
@@ -1 +1 @@
-export { getSafeApplicationUrl, getSafeAppHref, SAFE_NEW_TAB_REL } from "@homarr/common";
+export { getSafeApplicationUrl, SAFE_NEW_TAB_REL } from "@homarr/common";