Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(autopilots): hide webhook URL token by default (MUL-5374) (#6015)
Bohan Jiang50c89c709453
diff --git a/packages/core/autopilots/index.ts b/packages/core/autopilots/index.tsindex a48259a41c..f720976715 100644--- a/packages/core/autopilots/index.ts+++ b/packages/core/autopilots/index.ts@@ -18,4 +18,4 @@ export {useRotateAutopilotTriggerWebhookToken,useReplayAutopilotDelivery,} from "./mutations";-export { buildAutopilotWebhookUrl } from "./webhook";+export { buildAutopilotWebhookUrl, maskAutopilotWebhookUrl } from "./webhook";diff --git a/packages/core/autopilots/webhook.test.ts b/packages/core/autopilots/webhook.test.tsindex 4463350725..fbeb732210 100644--- a/packages/core/autopilots/webhook.test.ts+++ b/packages/core/autopilots/webhook.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from "vitest";-import { buildAutopilotWebhookUrl } from "./webhook";+import { buildAutopilotWebhookUrl, maskAutopilotWebhookUrl } from "./webhook";import type { AutopilotTrigger } from "../types";const baseTrigger: AutopilotTrigger = {@@ -71,3 +71,28 @@ describe("buildAutopilotWebhookUrl", () => {expect(buildAutopilotWebhookUrl({ trigger: baseTrigger })).toBe("/api/webhooks/autopilots/awt_abc");});});++describe("maskAutopilotWebhookUrl", () => {+ it("masks the token segment and keeps the rest readable", () => {+ const masked = maskAutopilotWebhookUrl("https://api.example/api/webhooks/autopilots/awt_abc");+ expect(masked).toBe("https://api.example/api/webhooks/autopilots/••••••••••••");+ expect(masked).not.toContain("awt_abc");+ });++ it("masks the token on a relative path", () => {+ expect(maskAutopilotWebhookUrl("/api/webhooks/autopilots/awt_abc")).toBe(+ "/api/webhooks/autopilots/••••••••••••",+ );+ });++ it("uses a fixed-width mask so the token length never leaks", () => {+ const short = maskAutopilotWebhookUrl("https://api.example/hooks/a");+ const long = maskAutopilotWebhookUrl("https://api.example/hooks/" + "z".repeat(64));+ expect(short).toBe(long);+ });++ it("masks the whole value when there is no separable last segment", () => {+ expect(maskAutopilotWebhookUrl("awt_abc")).toBe("••••••••••••");+ expect(maskAutopilotWebhookUrl("https://api.example/hooks/")).toBe("••••••••••••");+ });+});diff --git a/packages/core/autopilots/webhook.ts b/packages/core/autopilots/webhook.tsindex 4e7817a644..cc46efbec1 100644--- a/packages/core/autopilots/webhook.ts+++ b/packages/core/autopilots/webhook.ts@@ -41,3 +41,21 @@ function stripTrailingSlash(s: string | undefined): string {if (!s) return "";return s.endsWith("/") ? s.slice(0, -1) : s;}++/** Fixed-width run — never derived from the token, so the mask leaks no length. */+const WEBHOOK_URL_MASK = "••••••••••••";++/**+ * Mask the secret part of a webhook URL for display.+ *+ * Only the trailing token segment is a credential: anyone holding it can fire+ * the autopilot. The origin and the `/api/webhooks/autopilots/` prefix carry no+ * secret, so they stay readable and the value is still recognizable as this+ * trigger's URL while hidden. Falls back to the bare mask when the URL has no+ * separable last segment.+ */+export function maskAutopilotWebhookUrl(url: string): string {+ const cut = url.lastIndexOf("/");+ if (cut < 0 || cut === url.length - 1) return WEBHOOK_URL_MASK;+ return url.slice(0, cut + 1) + WEBHOOK_URL_MASK;+}diff --git a/packages/views/autopilots/components/autopilot-detail-page.tsx b/packages/views/autopilots/components/autopilot-detail-page.tsxindex cf7ba0593d..3d309cd626 100644--- a/packages/views/autopilots/components/autopilot-detail-page.tsx+++ b/packages/views/autopilots/components/autopilot-detail-page.tsx@@ -4,7 +4,7 @@ import { useState } from "react";import {Zap, Play, Clock, Plus, Trash2, CheckCircle2, XCircle, Loader2, Pencil,Ban, ChevronDown, ChevronRight,- Webhook, Copy, Check, RotateCw,+ Webhook, RotateCw,} from "lucide-react";import { useQuery } from "@tanstack/react-query";import { autopilotDetailOptions, autopilotRunsOptions, autopilotRunOptions } from "@multica/core/autopilots/queries";@@ -29,7 +29,6 @@ import { Skeleton } from "@multica/ui/components/ui/skeleton";import { Button } from "@multica/ui/components/ui/button";import { Switch } from "@multica/ui/components/ui/switch";import { cn } from "@multica/ui/lib/utils";-import { copyText } from "@multica/ui/lib/clipboard";import { toast } from "sonner";import {Dialog,@@ -47,6 +46,7 @@ import {AlertDialogTitle,} from "@multica/ui/components/ui/alert-dialog";import { ScheduleEditor } from "./schedule-editor/schedule-editor";+import { WebhookUrlField } from "./webhook-url-field";import { getDefaultScheduleConfig, type ScheduleConfig } from "./schedule-editor/model";import { browserTimezone } from "../../common/timezone-select";import { cronFields, parseCron, toCron } from "./schedule-editor/cron-mapping";@@ -262,7 +262,6 @@ function TriggerRow({ trigger, autopilotId, canWrite }: { trigger: AutopilotTrigconst [confirmOpen, setConfirmOpen] = useState(false);const [rotateOpen, setRotateOpen] = useState(false);const [deleting, setDeleting] = useState(false);- const [copied, setCopied] = useState(false);const handleDelete = async () => {setDeleting(true);@@ -294,17 +293,6 @@ function TriggerRow({ trigger, autopilotId, canWrite }: { trigger: AutopilotTrig}): null;- const handleCopy = async () => {- if (!webhookUrl) return;- if (await copyText(webhookUrl)) {- setCopied(true);- toast.success(t(($) => $.trigger_row.url_copied));- setTimeout(() => setCopied(false), 1500);- } else {- toast.error(t(($) => $.trigger_row.url_copy_failed));- }- };-const handleRotate = async () => {try {await rotateToken.mutateAsync({ autopilotId, triggerId: trigger.id });@@ -395,32 +383,27 @@ function TriggerRow({ trigger, autopilotId, canWrite }: { trigger: AutopilotTrig</div>)}{showWebhookUrlRow && (- <div className="mt-1.5 flex items-center gap-1.5">- <code className="flex-1 min-w-0 truncate rounded bg-muted px-2 py-1 text-xs font-mono text-foreground">- {webhookUrl}- </code>- <Button- size="icon"- variant="ghost"- className="h-7 w-7 shrink-0"- onClick={handleCopy}- title={t(($) => $.trigger_row.copy_url)}- >- {copied ? <Check className="h-3.5 w-3.5 text-emerald-500" /> : <Copy className="h-3.5 w-3.5 text-muted-foreground" />}- </Button>- {canWrite && (- <Button- size="icon"- variant="ghost"- className="h-7 w-7 shrink-0"- onClick={() => setRotateOpen(true)}- title={t(($) => $.trigger_row.rotate_url)}- disabled={rotateToken.isPending}- >- <RotateCw className={cn("h-3.5 w-3.5 text-muted-foreground", rotateToken.isPending && "animate-spin")} />- </Button>- )}- {deleteButton}+ <div className="mt-1.5">+ <WebhookUrlField+ url={webhookUrl}+ actions={+ <>+ {canWrite && (+ <Button+ size="icon"+ variant="ghost"+ className="h-7 w-7 shrink-0"+ onClick={() => setRotateOpen(true)}+ title={t(($) => $.trigger_row.rotate_url)}+ disabled={rotateToken.isPending}+ >+ <RotateCw className={cn("h-3.5 w-3.5 text-muted-foreground", rotateToken.isPending && "animate-spin")} />+ </Button>+ )}+ {deleteButton}+ </>+ }+ /></div>)}</div>diff --git a/packages/views/autopilots/components/autopilot-dialog.tsx b/packages/views/autopilots/components/autopilot-dialog.tsxindex 4acb2a2563..1c590f880e 100644--- a/packages/views/autopilots/components/autopilot-dialog.tsx+++ b/packages/views/autopilots/components/autopilot-dialog.tsx@@ -8,7 +8,6 @@ import {ChevronDown,ChevronRight,Clock,- Copy,FilePlus2,FolderKanban,Maximize2,@@ -21,7 +20,6 @@ import {Zap,} from "lucide-react";import { cn } from "@multica/ui/lib/utils";-import { copyText } from "@multica/ui/lib/clipboard";import {Dialog,DialogContent,@@ -69,6 +67,7 @@ import { browserTimezone } from "../../common/timezone-select";import { parseCron, toCron } from "./schedule-editor/cron-mapping";import { useScheduleSubmitGate } from "./schedule-editor/validate";import { WebhookEventFilterSection } from "./webhook-event-filter-section";+import { WebhookUrlField } from "./webhook-url-field";import { useT } from "../../i18n";import { formatSchedulePartialFailureToast } from "./autopilot-dialog-toast";import type { WebhookEventFilter } from "@multica/core/types";@@ -919,7 +918,6 @@ function WebhookCreatedPanel({onClose: () => void;}) {const { t } = useT("autopilots");- const [copied, setCopied] = useState(false);// Same URL composition the trigger row uses: prefer the server-provided// webhook_url, fall back to apiBaseUrl + webhook_path, then origin + path.@@ -930,17 +928,6 @@ function WebhookCreatedPanel({currentOrigin: typeof window !== "undefined" ? window.location.origin : undefined,}) ?? "";- const handleCopy = async () => {- if (!url) return;- if (await copyText(url)) {- setCopied(true);- toast.success(t(($) => $.trigger_row.url_copied));- setTimeout(() => setCopied(false), 1500);- } else {- toast.error(t(($) => $.trigger_row.url_copy_failed));- }- };-return (<><div className="flex-1 min-h-0 overflow-y-auto px-8 py-10">@@ -961,24 +948,7 @@ function WebhookCreatedPanel({<div className="text-[11px] font-semibold tracking-[0.08em] text-muted-foreground uppercase mb-2">{t(($) => $.trigger_row.webhook_url_label)}</div>- <div className="flex items-stretch gap-1.5">- <code className="flex-1 min-w-0 truncate rounded-md border bg-muted px-3 py-2 text-xs font-mono text-foreground">- {url}- </code>- <Button- size="icon"- variant="outline"- className="h-9 w-9 shrink-0"- onClick={handleCopy}- title={t(($) => $.trigger_row.copy_url)}- >- {copied ? (- <Check className="size-4 text-emerald-500" />- ) : (- <Copy className="size-4 text-muted-foreground" />- )}- </Button>- </div>+ <WebhookUrlField url={url} size="md" /></div><div className="rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-400 leading-relaxed">diff --git a/packages/views/autopilots/components/webhook-url-field.test.tsx b/packages/views/autopilots/components/webhook-url-field.test.tsxnew file mode 100644index 0000000000..43d757934c--- /dev/null+++ b/packages/views/autopilots/components/webhook-url-field.test.tsx@@ -0,0 +1,74 @@+import { describe, it, expect, beforeAll, vi } from "vitest";+import { screen, fireEvent } from "@testing-library/react";+import { renderWithI18n } from "../../test/i18n";+import { WebhookUrlField } from "./webhook-url-field";++// sonner.toast is a fire-and-forget side-effect; stub it so Copy doesn't blow+// up on toast invocation.+vi.mock("sonner", () => ({+ toast: { success: vi.fn(), error: vi.fn() },+}));++const writeText = vi.fn().mockResolvedValue(undefined);++// jsdom doesn't provide navigator.clipboard by default. Stub it once.+beforeAll(() => {+ Object.assign(navigator, { clipboard: { writeText } });+});++const URL = "https://api.example.com/api/webhooks/autopilots/awt_supersecret";++describe("WebhookUrlField", () => {+ it("hides the token by default — the plaintext is not in the DOM", () => {+ const { container } = renderWithI18n(<WebhookUrlField url={URL} />);+ expect(container.textContent).not.toContain("awt_supersecret");+ expect(screen.getByText(/api\/webhooks\/autopilots\/•+/)).toBeInTheDocument();+ });++ it("reveals the full URL when the masked value is clicked", () => {+ const { container } = renderWithI18n(<WebhookUrlField url={URL} />);+ fireEvent.click(screen.getByRole("button", { name: "Webhook URL hidden — click to show" }));+ expect(container.textContent).toContain(URL);+ });++ it("hides again via the toggle", () => {+ const { container } = renderWithI18n(<WebhookUrlField url={URL} />);+ fireEvent.click(screen.getByRole("button", { name: "Webhook URL hidden — click to show" }));+ fireEvent.click(screen.getByRole("button", { name: "Hide URL" }));+ expect(container.textContent).not.toContain("awt_supersecret");+ });++ it("copies the real URL while it is still hidden", async () => {+ writeText.mockClear();+ const { container } = renderWithI18n(<WebhookUrlField url={URL} />);+ fireEvent.click(screen.getByRole("button", { name: "Copy URL" }));+ expect(writeText).toHaveBeenCalledWith(URL);+ expect(container.textContent).not.toContain("awt_supersecret");+ });++ it("re-hides when the URL changes — a rotated token is never inherited revealed", () => {+ const rotated = "https://api.example.com/api/webhooks/autopilots/awt_rotatedsecret";+ const { container, rerender } = renderWithI18n(<WebhookUrlField url={URL} />);+ fireEvent.click(screen.getByRole("button", { name: "Webhook URL hidden — click to show" }));+ expect(container.textContent).toContain(URL);++ // Rotate: the row stays mounted and only the prop changes. The new+ // credential must come back masked, with no revealed frame in between.+ rerender(<WebhookUrlField url={rotated} />);+ expect(container.textContent).not.toContain("awt_rotatedsecret");+ expect(+ screen.getByRole("button", { name: "Webhook URL hidden — click to show" }),+ ).toBeInTheDocument();++ // The new URL can still be revealed on its own.+ fireEvent.click(screen.getByRole("button", { name: "Webhook URL hidden — click to show" }));+ expect(container.textContent).toContain(rotated);+ });++ it("renders trailing actions alongside the field", () => {+ renderWithI18n(+ <WebhookUrlField url={URL} actions={<button type="button">Rotate</button>} />,+ );+ expect(screen.getByRole("button", { name: "Rotate" })).toBeInTheDocument();+ });+});diff --git a/packages/views/autopilots/components/webhook-url-field.tsx b/packages/views/autopilots/components/webhook-url-field.tsxnew file mode 100644index 0000000000..8e3fcf6202--- /dev/null+++ b/packages/views/autopilots/components/webhook-url-field.tsx@@ -0,0 +1,125 @@+"use client";++import { useState, type ReactNode } from "react";+import { Check, Copy, Eye, EyeOff } from "lucide-react";+import { toast } from "sonner";+import { maskAutopilotWebhookUrl } from "@multica/core/autopilots";+import { Button } from "@multica/ui/components/ui/button";+import { cn } from "@multica/ui/lib/utils";+import { copyText } from "@multica/ui/lib/clipboard";+import { useT } from "../../i18n";++const SIZES = {+ // Trigger row on the detail page — compact, sits inline with the row actions.+ sm: {+ row: "items-center",+ value: "rounded bg-muted px-2 py-1 text-xs",+ button: "h-7 w-7",+ buttonVariant: "ghost",+ icon: "h-3.5 w-3.5",+ },+ // Post-create panel — larger standalone field.+ md: {+ row: "items-stretch",+ value: "rounded-md border bg-muted px-3 py-2 text-xs",+ button: "h-9 w-9",+ buttonVariant: "outline",+ icon: "size-4",+ },+} as const;++interface WebhookUrlFieldProps {+ url: string;+ size?: keyof typeof SIZES;+ /** Extra controls rendered after Copy (rotate, delete). */+ actions?: ReactNode;+}++/**+ * Webhook URL display that hides the token by default.+ *+ * The URL is a bearer credential: anyone who reads it off a screen share or a+ * screenshot can fire the autopilot. So the masked form is what renders — the+ * plaintext token is never in the DOM until the user asks for it, which a+ * CSS-only blur would not give us. Copy still works while hidden, so the common+ * case never needs a reveal at all.+ */+export function WebhookUrlField({ url, size = "sm", actions }: WebhookUrlFieldProps) {+ const { t } = useT("autopilots");+ // A reveal authorizes one specific URL, not the field. Rotating the token+ // swaps `url` under a mounted row, and the new credential has to be revealed+ // again on its own — a bare boolean would hand the old grant to the new+ // secret, exposing it exactly when the user rotated to contain a leak.+ // Deriving this during render (rather than resetting in an effect) means the+ // new token never reaches the DOM, not even for the pre-effect frame.+ const [revealedUrl, setRevealedUrl] = useState<string | null>(null);+ const [copied, setCopied] = useState(false);+ const revealed = revealedUrl === url;+ const s = SIZES[size];++ const handleCopy = async () => {+ if (!url) return;+ if (await copyText(url)) {+ setCopied(true);+ toast.success(t(($) => $.trigger_row.url_copied));+ setTimeout(() => setCopied(false), 1500);+ } else {+ toast.error(t(($) => $.trigger_row.url_copy_failed));+ }+ };++ const valueClassName = cn(+ "flex-1 min-w-0 truncate font-mono text-foreground",+ s.value,+ );++ return (+ <div className={cn("flex gap-1.5", s.row)}>+ {revealed ? (+ <code className={valueClassName}>{url}</code>+ ) : (+ // Click-to-reveal lives on the value itself. Once revealed it goes back+ // to plain text so the URL stays selectable — a toggle button there+ // would swallow the drag-select.+ <button+ type="button"+ onClick={() => setRevealedUrl(url)}+ className={cn(valueClassName, "text-left cursor-pointer transition-colors hover:bg-muted/70")}+ title={t(($) => $.trigger_row.show_url)}+ aria-label={t(($) => $.trigger_row.hidden_url_aria)}+ >+ {maskAutopilotWebhookUrl(url)}+ </button>+ )}+ <Button+ size="icon"+ variant={s.buttonVariant}+ className={cn("shrink-0", s.button)}+ onClick={() => setRevealedUrl(revealed ? null : url)}+ title={revealed ? t(($) => $.trigger_row.hide_url) : t(($) => $.trigger_row.show_url)}+ aria-label={revealed ? t(($) => $.trigger_row.hide_url) : t(($) => $.trigger_row.show_url)}+ >+ {revealed ? (+ <EyeOff className={cn(s.icon, "text-muted-foreground")} />+ ) : (+ <Eye className={cn(s.icon, "text-muted-foreground")} />+ )}+ </Button>+ <Button+ size="icon"+ variant={s.buttonVariant}+ className={cn("shrink-0", s.button)}+ onClick={handleCopy}+ title={t(($) => $.trigger_row.copy_url)}+ aria-label={t(($) => $.trigger_row.copy_url)}+ >+ {copied ? (+ <Check className={cn(s.icon, "text-emerald-500")} />+ ) : (+ <Copy className={cn(s.icon, "text-muted-foreground")} />+ )}+ </Button>+ {actions}+ </div>+ );+}diff --git a/packages/views/locales/en/autopilots.json b/packages/views/locales/en/autopilots.jsonindex c17e2ef91c..0f1bb3a236 100644--- a/packages/views/locales/en/autopilots.json+++ b/packages/views/locales/en/autopilots.json@@ -163,6 +163,9 @@"deprecated_badge": "Deprecated","next_label": "Next: {{date}}","webhook_url_label": "Webhook URL",+ "show_url": "Show URL",+ "hide_url": "Hide URL",+ "hidden_url_aria": "Webhook URL hidden — click to show","copy_url": "Copy URL","url_copied": "Webhook URL copied","url_copy_failed": "Failed to copy",diff --git a/packages/views/locales/ja/autopilots.json b/packages/views/locales/ja/autopilots.jsonindex 91a2a61a10..9476fa9c0e 100644--- a/packages/views/locales/ja/autopilots.json+++ b/packages/views/locales/ja/autopilots.json@@ -163,6 +163,9 @@"deprecated_badge": "非推奨","next_label": "次回: {{date}}","webhook_url_label": "Webhook URL",+ "show_url": "URL を表示",+ "hide_url": "URL を非表示",+ "hidden_url_aria": "Webhook URL は非表示です — クリックして表示","copy_url": "URL をコピー","url_copied": "Webhook URL をコピーしました","url_copy_failed": "URL をコピーできませんでした",diff --git a/packages/views/locales/ko/autopilots.json b/packages/views/locales/ko/autopilots.jsonindex 58b337bdb3..866fef3c6a 100644--- a/packages/views/locales/ko/autopilots.json+++ b/packages/views/locales/ko/autopilots.json@@ -163,6 +163,9 @@"deprecated_badge": "지원 중단","next_label": "다음: {{date}}","webhook_url_label": "Webhook URL",+ "show_url": "URL 표시",+ "hide_url": "URL 숨기기",+ "hidden_url_aria": "Webhook URL이 숨겨져 있습니다 — 클릭하여 표시","copy_url": "URL 복사","url_copied": "Webhook URL을 복사했습니다","url_copy_failed": "URL을 복사하지 못했습니다",diff --git a/packages/views/locales/zh-Hans/autopilots.json b/packages/views/locales/zh-Hans/autopilots.jsonindex be4a359017..cc4cc1e928 100644--- a/packages/views/locales/zh-Hans/autopilots.json+++ b/packages/views/locales/zh-Hans/autopilots.json@@ -163,6 +163,9 @@"deprecated_badge": "已弃用","next_label": "下次:{{date}}","webhook_url_label": "Webhook URL",+ "show_url": "显示 URL",+ "hide_url": "隐藏 URL",+ "hidden_url_aria": "Webhook URL 已隐藏 — 点击显示","copy_url": "复制 URL","url_copied": "已复制 Webhook URL","url_copy_failed": "复制失败",