Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(web): reject non-http URLs in attachment and issue-link nodes

Andrej700da1b2cef4
diff --git a/apps/web/src/components/task/extensions/attachment-card.tsx b/apps/web/src/components/task/extensions/attachment-card.tsx
index b28a2863d..c5861f6dd 100644
--- a/apps/web/src/components/task/extensions/attachment-card.tsx
+++ b/apps/web/src/components/task/extensions/attachment-card.tsx
@@ -2,6 +2,7 @@ import { mergeAttributes, Node } from "@tiptap/core";
import type { NodeViewProps } from "@tiptap/react";
import { NodeViewWrapper, ReactNodeViewRenderer } from "@tiptap/react";
import { FileText } from "lucide-react";
+import { escapeHtml, isValidUrl } from "./url-safety";
function formatBytes(size: number) {
if (!Number.isFinite(size) || size <= 0) return "";
@@ -13,7 +14,8 @@ function formatBytes(size: number) {
}
function AttachmentCardView({ node }: NodeViewProps) {
- const url = String(node.attrs.url || "");
+ const rawUrl = String(node.attrs.url || "");
+ const url = isValidUrl(rawUrl) ? rawUrl : "";
const filename = String(node.attrs.filename || "Attachment");
const mimeType = String(node.attrs.mimeType || "");
const size = Number(node.attrs.size || 0);
@@ -21,7 +23,7 @@ function AttachmentCardView({ node }: NodeViewProps) {
return (
<NodeViewWrapper as="span" className="kaneo-attachment-node">
<a
- href={url}
+ href={url || undefined}
target="_blank"
rel="noopener noreferrer"
className="kaneo-attachment-card"
@@ -102,6 +104,6 @@ export const AttachmentCard = Node.create({
if (!url) return "";
- return `\n<kaneo-attachment url="${url}" filename="${filename}" mime-type="${mimeType}" size="${size}" />\n`;
+ return `\n<kaneo-attachment url="${escapeHtml(url)}" filename="${escapeHtml(filename)}" mime-type="${escapeHtml(mimeType)}" size="${size}" />\n`;
},
});
diff --git a/apps/web/src/components/task/extensions/embed-block.ts b/apps/web/src/components/task/extensions/embed-block.ts
index 22eb622be..4f8d49248 100644
--- a/apps/web/src/components/task/extensions/embed-block.ts
+++ b/apps/web/src/components/task/extensions/embed-block.ts
@@ -1,25 +1,9 @@
import { mergeAttributes, Node } from "@tiptap/core";
import { i18n } from "@/lib/i18n";
+import { escapeHtml, isValidUrl } from "./url-safety";
type EmbedMode = "embed" | "link";
-function isValidUrl(value: string) {
- try {
- const url = new URL(value);
- return url.protocol === "http:" || url.protocol === "https:";
- } catch {
- return false;
- }
-}
-
-function escapeHtml(value: string) {
- return value
- .replace(/&/g, "&amp;")
- .replace(/"/g, "&quot;")
- .replace(/</g, "&lt;")
- .replace(/>/g, "&gt;");
-}
-
function getEmbedSource(url: string) {
try {
const parsed = new URL(url);
diff --git a/apps/web/src/components/task/extensions/kaneo-issue-link.tsx b/apps/web/src/components/task/extensions/kaneo-issue-link.tsx
index 31bd1c53b..7616daf1e 100644
--- a/apps/web/src/components/task/extensions/kaneo-issue-link.tsx
+++ b/apps/web/src/components/task/extensions/kaneo-issue-link.tsx
@@ -10,6 +10,7 @@ import {
} from "@/components/ui/preview-card";
import getProject from "@/fetchers/project/get-project";
import getTask from "@/fetchers/task/get-task";
+import { escapeHtml, isValidUrl } from "./url-safety";
function parseTaskRouteFromUrl(url: string) {
try {
@@ -70,18 +71,19 @@ function KaneoIssueLinkView({ node }: NodeViewProps) {
? t(`tasks:priority.${task.priority}`)
: t("tasks:priority.no-priority");
const assignee = task?.assigneeName || t("tasks:assignee.unassigned");
- const href =
+ const resolvedHref =
taskRoute?.workspaceId && taskRoute?.projectId && task?.id
? `/dashboard/workspace/${taskRoute.workspaceId}/project/${taskRoute.projectId}/task/${task.id}`
: url;
- const isInternal = href.startsWith("/");
+ const isInternal = resolvedHref.startsWith("/");
+ const href = isInternal || isValidUrl(resolvedHref) ? resolvedHref : "";
return (
<NodeViewWrapper as="span" className="kaneo-issue-link-node">
<HoverCard openDelay={160} closeDelay={120}>
<HoverCardTrigger asChild>
<a
- href={href}
+ href={href || undefined}
target={isInternal ? undefined : "_blank"}
rel={isInternal ? undefined : "noopener noreferrer"}
className="kaneo-issue-link-chip"
@@ -168,6 +170,6 @@ export const KaneoIssueLink = Node.create({
const issueKey = String(node.attrs?.issueKey || "");
const taskId = String(node.attrs?.taskId || "");
if (!url) return "";
- return `\n<kaneo-issue-link url="${url}" issue-key="${issueKey}" task-id="${taskId}" />\n`;
+ return `\n<kaneo-issue-link url="${escapeHtml(url)}" issue-key="${escapeHtml(issueKey)}" task-id="${escapeHtml(taskId)}" />\n`;
},
});
diff --git a/apps/web/src/components/task/extensions/url-safety.ts b/apps/web/src/components/task/extensions/url-safety.ts
new file mode 100644
index 000000000..9fbdbe33f
--- /dev/null
+++ b/apps/web/src/components/task/extensions/url-safety.ts
@@ -0,0 +1,16 @@
+export function isValidUrl(value: string) {
+ try {
+ const url = new URL(value);
+ return url.protocol === "http:" || url.protocol === "https:";
+ } catch {
+ return false;
+ }
+}
+
+export function escapeHtml(value: string) {
+ return value
+ .replace(/&/g, "&amp;")
+ .replace(/"/g, "&quot;")
+ .replace(/</g, "&lt;")
+ .replace(/>/g, "&gt;");
+}