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(editor): reject active embed URL schemes (#1376)

Tin Sever5630fd0e5fb0
diff --git a/apps/web/src/components/task/extensions/embed-block.ts b/apps/web/src/components/task/extensions/embed-block.ts
index d15894464..22eb622be 100644
--- a/apps/web/src/components/task/extensions/embed-block.ts
+++ b/apps/web/src/components/task/extensions/embed-block.ts
@@ -5,9 +5,8 @@ type EmbedMode = "embed" | "link";
function isValidUrl(value: string) {
try {
- // eslint-disable-next-line no-new
- new URL(value);
- return true;
+ const url = new URL(value);
+ return url.protocol === "http:" || url.protocol === "https:";
} catch {
return false;
}
@@ -89,6 +88,14 @@ export const EmbedBlock = Node.create({
contenteditable: "false",
});
+ if (!isValidUrl(url)) {
+ return [
+ "div",
+ attrs,
+ ["span", { class: "kaneo-embed-invalid-link" }, url],
+ ];
+ }
+
if (embedSource) {
return [
"div",
@@ -142,7 +149,9 @@ export const EmbedBlock = Node.create({
) {
const url = String(node.attrs?.url || "");
const mode = node.attrs?.mode === "link" ? "link" : "embed";
- if (!isValidUrl(url)) return "";
+ if (!isValidUrl(url)) {
+ return `\n<span class="kaneo-embed-invalid-link">${escapeHtml(url)}</span>\n`;
+ }
return `\n<kaneo-embed url="${escapeHtml(url)}" mode="${mode}" />\n`;
},
});