The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Expand API log route coverage and mask sensitive request/response fields.
Kiran K60d204c0b6fc
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/billing/manage/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/billing/manage/route.tsindex dea771f30d..a2a0dfd1e5 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/billing/manage/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/manage/route.ts@@ -24,7 +24,7 @@ export const POST = withWorkspace(customer: workspace.stripeId,return_url: `${APP_DOMAIN}/${workspace.slug}/settings/billing`,});- return NextResponse.json(url);+ return NextResponse.json({ url });} catch (error) {throw new DubApiError({code: "bad_request",diff --git a/apps/web/app/api/workspaces/[idOrSlug]/invites/reset/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/invites/reset/route.tsindex e45b813efd..c4f1e5df37 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/invites/reset/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/invites/reset/route.ts@@ -5,16 +5,19 @@ import { NextResponse } from "next/server";export const POST = withWorkspace(async ({ workspace }) => {- const response = await prisma.project.update({+ const { inviteCode } = await prisma.project.update({where: {id: workspace.id,},data: {inviteCode: nanoid(24),},+ select: {+ inviteCode: true,+ },});- return NextResponse.json(response);+ return NextResponse.json({ inviteCode });},{requiredPermissions: ["workspaces.write"],diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/logs/[logId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/logs/[logId]/page-client.tsxindex 7f171d3db7..5af5f061cd 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/logs/[logId]/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/logs/[logId]/page-client.tsx@@ -76,6 +76,16 @@ export function LogDetailPageClient() {);}+function hasJsonBody(raw: string | null | undefined) {+ if (!raw) return false;++ try {+ return JSON.parse(raw) != null;+ } catch {+ return true;+ }+}+function LogDetailSkeleton() {return (<div className="flex flex-col gap-6 lg:flex-row">@@ -245,23 +255,17 @@ function LogDetailContent({ log }: { log: EnrichedApiLog }) {/></div>)}- {log.method !== "DELETE" && (+ {hasJsonBody(log.request_body) && (<div className="flex flex-col gap-2"><h3 className="text-content-emphasis text-lg font-semibold">Request body</h3>- {highlightedBodies.request ? (- <div- className="shiki-wrapper max-h-[800px] overflow-auto rounded-xl border border-neutral-200 bg-white p-4 text-sm"- dangerouslySetInnerHTML={{- __html: highlightedBodies.request,- }}- />- ) : (- <div className="rounded-xl border border-neutral-200 bg-white p-4 font-mono text-xs text-neutral-500">- No request body- </div>- )}+ <div+ className="shiki-wrapper max-h-[800px] overflow-auto rounded-xl border border-neutral-200 bg-white p-4 text-sm"+ dangerouslySetInnerHTML={{+ __html: highlightedBodies.request,+ }}+ /></div>)}</div>diff --git a/apps/web/lib/api-logs/capture-request-log.ts b/apps/web/lib/api-logs/capture-request-log.tsindex 0b1c7cd713..92250c8e69 100644--- a/apps/web/lib/api-logs/capture-request-log.ts+++ b/apps/web/lib/api-logs/capture-request-log.ts@@ -4,6 +4,7 @@ import { Session } from "../auth/utils";import { HTTP_MUTATION_METHODS, ROUTE_PATTERNS } from "./constants";import {maskSensitiveFields,+ SENSITIVE_REQUEST_FIELDS_BY_ROUTE,SENSITIVE_RESPONSE_FIELDS_BY_ROUTE,} from "./mask-sensitive-fields";import { parseQueryParams } from "./query-params";@@ -86,6 +87,19 @@ export async function captureRequestLog({const queryParams = parseQueryParams(url.searchParams);+ // Mask sensitive fields in the request body+ if (requestBody) {+ const sensitiveRequestFields =+ SENSITIVE_REQUEST_FIELDS_BY_ROUTE[routePattern];++ if (sensitiveRequestFields) {+ requestBody = maskSensitiveFields({+ body: requestBody,+ keys: sensitiveRequestFields,+ });+ }+ }+// Mask sensitive fields in the response bodyif (responseBody) {const sensitiveResponseFields =diff --git a/apps/web/lib/api-logs/constants.ts b/apps/web/lib/api-logs/constants.tsindex 73a774032d..9e616eefb7 100644--- a/apps/web/lib/api-logs/constants.ts+++ b/apps/web/lib/api-logs/constants.ts@@ -36,6 +36,7 @@ export const ROUTE_PATTERNS = [// Links"/links/bulk","/links/upsert",+ "/links/sync","/links/:linkId/transfer","/links/:linkId","/links",@@ -117,7 +118,22 @@ export const ROUTE_PATTERNS = ["/oauth/apps/:appId","/oauth/apps",+ // Integrations+ "/integrations/uninstall",+ "/stripe/integration",+// Workspaces+ "/workspaces/:id/users",+ "/workspaces/:id/invites/reset",+ "/workspaces/:id/invites",+ "/workspaces/:id/saml",+ "/workspaces/:id/scim",+ "/workspaces/:id/billing/activate-paid-plan",+ "/workspaces/:id/billing/cancel",+ "/workspaces/:id/billing/manage",+ "/workspaces/:id/billing/payment-methods",+ "/workspaces/:id/billing/retry-payment",+ "/workspaces/:id/billing/upgrade","/workspaces/:id",] as const;diff --git a/apps/web/lib/api-logs/mask-sensitive-fields.ts b/apps/web/lib/api-logs/mask-sensitive-fields.tsindex 4d8205abf4..faf0ba637b 100644--- a/apps/web/lib/api-logs/mask-sensitive-fields.ts+++ b/apps/web/lib/api-logs/mask-sensitive-fields.ts@@ -10,6 +10,23 @@ export const SENSITIVE_RESPONSE_FIELDS_BY_ROUTE = {"/oauth/apps": ["clientSecret"],"/webhooks": ["secret"],"/webhooks/:webhookId": ["secret"],+ "/workspaces/:id/saml": ["clientSecret"],+ "/workspaces/:id/scim": [+ "secret",+ "google_access_token",+ "google_refresh_token",+ ],+ "/workspaces/:id/invites/reset": ["inviteCode"],+ "/workspaces/:id/billing/upgrade": ["url", "id"],+ "/workspaces/:id/billing/payment-methods": ["url"],+ "/workspaces/:id/billing/manage": ["url"],+ "/workspaces/:id": ["inviteCode"],+} as const;++// Map of route pattern -> request body fields that should be masked before logging.+export const SENSITIVE_REQUEST_FIELDS_BY_ROUTE = {+ "/workspaces/:id/saml": ["encodedRawMetadata"],+ "/workspaces/:id": ["publishableKey"],} as const;// Stripe-style partial mask: visible prefix through the last `_` (e.g. `sk_live_`),diff --git a/apps/web/lib/api-logs/query-params.ts b/apps/web/lib/api-logs/query-params.tsindex eca3936d14..75bd414259 100644--- a/apps/web/lib/api-logs/query-params.ts+++ b/apps/web/lib/api-logs/query-params.ts@@ -18,6 +18,8 @@ const SENSITIVE_QUERY_PARAM_KEYS = new Set(["refresh_token","client_secret","client_id",+ "clientsecret",+ "clientid","key",]);diff --git a/apps/web/ui/logs/logs-table.tsx b/apps/web/ui/logs/logs-table.tsxindex 0407855312..0ac22b0ded 100644--- a/apps/web/ui/logs/logs-table.tsx+++ b/apps/web/ui/logs/logs-table.tsx@@ -110,10 +110,7 @@ export function LogsTable() {id: "path",header: "Endpoint",cell: ({ row }: { row: Row<EnrichedApiLog> }) => (- <span- className="truncate"- title={row.original.route_pattern || undefined}- >+ <span className="block min-w-0 truncate" title={row.original.path}>{row.original.path}</span>),@@ -123,6 +120,7 @@ export function LogsTable() {}),},size: 300,+ maxSize: 360,},{id: "method",diff --git a/apps/web/ui/workspaces/manage-subscription-button.tsx b/apps/web/ui/workspaces/manage-subscription-button.tsxindex eec87a63e8..3eaf03d83a 100644--- a/apps/web/ui/workspaces/manage-subscription-button.tsx+++ b/apps/web/ui/workspaces/manage-subscription-button.tsx@@ -24,7 +24,7 @@ export default function ManageSubscriptionButton(props: ButtonProps) {method: "POST",}).then(async (res) => {if (res.ok) {- const url = await res.json();+ const { url } = await res.json();router.push(url);} else {const { error } = await res.json();diff --git a/apps/web/ui/workspaces/subscription-menu.tsx b/apps/web/ui/workspaces/subscription-menu.tsxindex c4e0734427..3afa4c3ff1 100644--- a/apps/web/ui/workspaces/subscription-menu.tsx+++ b/apps/web/ui/workspaces/subscription-menu.tsx@@ -48,7 +48,7 @@ export default function SubscriptionMenu() {}).then(async (res) => {if (res.ok) {- const url = await res.json();+ const { url } = await res.json();router.push(url);} else {const { error } = await res.json();