Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(web): only accept Loom share and embed links in the import launcher
Richie McIlroy29d24b899e1e
diff --git a/apps/web/__tests__/unit/loom-import-href.test.ts b/apps/web/__tests__/unit/loom-import-href.test.tsnew file mode 100644index 000000000..5e9061b78--- /dev/null+++ b/apps/web/__tests__/unit/loom-import-href.test.ts@@ -0,0 +1,71 @@+import { describe, expect, it } from "vitest";+import { buildLoomImportHref, isLoomShareUrl } from "@/lib/loom-import-href";++describe("isLoomShareUrl", () => {+ it("accepts share and embed links with a video id", () => {+ expect(+ isLoomShareUrl(+ "https://www.loom.com/share/0123456789abcdef0123456789abcdef",+ ),+ ).toBe(true);+ expect(isLoomShareUrl("https://loom.com/embed/0123456789abcdef")).toBe(+ true,+ );+ expect(+ isLoomShareUrl(+ " https://www.loom.com/share/0123456789abcdef?sid=abc&t=12 ",+ ),+ ).toBe(true);+ });++ it("rejects Loom pages that are not a video", () => {+ expect(isLoomShareUrl("https://www.loom.com/")).toBe(false);+ expect(isLoomShareUrl("https://www.loom.com/looms/videos")).toBe(false);+ expect(isLoomShareUrl("https://www.loom.com/share/")).toBe(false);+ expect(isLoomShareUrl("https://www.loom.com/share/short")).toBe(false);+ expect(isLoomShareUrl("https://www.loom.com/pricing")).toBe(false);+ });++ it("rejects other hosts and junk", () => {+ expect(isLoomShareUrl("https://notloom.com/share/0123456789abcdef")).toBe(+ false,+ );+ expect(+ isLoomShareUrl("https://loom.com.evil.example/share/0123456789abcdef"),+ ).toBe(false);+ expect(isLoomShareUrl("not a loom link")).toBe(false);+ expect(isLoomShareUrl("")).toBe(false);+ });+});++describe("buildLoomImportHref", () => {+ const loomUrl = "https://www.loom.com/share/0123456789abcdef";++ it("links signed-in visitors straight to the importer", () => {+ expect(buildLoomImportHref({ signedIn: true })).toBe(+ "/dashboard/import/loom",+ );+ expect(buildLoomImportHref({ signedIn: true, loomUrl })).toBe(+ `/dashboard/import/loom?url=${encodeURIComponent(loomUrl)}`,+ );+ expect(buildLoomImportHref({ signedIn: true, mode: "csv" })).toBe(+ "/dashboard/import/loom?mode=csv",+ );+ });++ it("wraps the importer path in a signup next param when signed out", () => {+ const href = buildLoomImportHref({+ signedIn: false,+ loomUrl,+ mode: "csv",+ });+ const next = new URL(href, "https://cap.so").searchParams.get("next");+ expect(href.startsWith("/signup?next=")).toBe(true);+ expect(next).toBe(+ `/dashboard/import/loom?url=${encodeURIComponent(loomUrl)}&mode=csv`,+ );+ expect(new URL(next ?? "", "https://cap.so").searchParams.get("url")).toBe(+ loomUrl,+ );+ });+});diff --git a/apps/web/lib/loom-import-href.ts b/apps/web/lib/loom-import-href.tsindex 06560e635..cb6d1e294 100644--- a/apps/web/lib/loom-import-href.ts+++ b/apps/web/lib/loom-import-href.ts@@ -1,5 +1,8 @@export const LOOM_IMPORT_PATH = "/dashboard/import/loom";+const LOOM_VIDEO_ROUTES = new Set(["share", "embed"]);+const MIN_LOOM_VIDEO_ID_LENGTH = 10;+export type LoomImportMode = "single" | "csv";export type LoomImportTarget = {@@ -10,8 +13,16 @@ export type LoomImportTarget = {export const isLoomShareUrl = (value: string) => {try {- const { hostname } = new URL(value.trim());- return hostname === "loom.com" || hostname.endsWith(".loom.com");+ const { hostname, pathname } = new URL(value.trim());+ if (hostname !== "loom.com" && !hostname.endsWith(".loom.com")) {+ return false;+ }+ const [route, videoId] = pathname.split("/").filter(Boolean);+ return (+ route !== undefined &&+ LOOM_VIDEO_ROUTES.has(route) &&+ (videoId?.length ?? 0) >= MIN_LOOM_VIDEO_ID_LENGTH+ );} catch {return false;}