The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add getIntegrationGuideMarkdown
Kiran Kbdb9c114a32d
diff --git a/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/connect/page.tsx b/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/connect/page.tsxindex 8a072ce575..b75de0eb6a 100644--- a/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/connect/page.tsx+++ b/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/connect/page.tsx@@ -1,9 +1,8 @@+import { getIntegrationGuideMarkdown } from "@/lib/get-integration-guide-markdown";import { Guide } from "@/ui/guides/guide";import { GuideList } from "@/ui/guides/guide-list";import { guides, IntegrationGuide } from "@/ui/guides/integrations";-import { readFileSync } from "fs";import { notFound } from "next/navigation";-import { join } from "path";import { Suspense } from "react";import { StepPage } from "../step-page";@@ -11,7 +10,7 @@ export default async function Page({searchParams,}: {searchParams: {- guide: string;+ guide?: string;};}) {let { guide } = searchParams;@@ -25,7 +24,7 @@ export default async function Page({notFound();}- markdown = getMarkdown(selectedGuide.key);+ markdown = await getIntegrationGuideMarkdown(selectedGuide.key);if (!markdown) {notFound();@@ -50,18 +49,3 @@ export default async function Page({</StepPage>);}--function getMarkdown(guideKey: string): string | null {- const markdownPath = join(- process.cwd(),- "integration-guides",- `${guideKey}.md`,- );-- try {- return readFileSync(markdownPath, "utf-8");- } catch (error) {- console.warn(`Guide content not found for: ${guideKey}`);- return null;- }-}diff --git a/apps/web/app/(ee)/app.dub.co/[slug]/(guide)/tracking-guide/page.tsx b/apps/web/app/(ee)/app.dub.co/[slug]/(guide)/tracking-guide/page.tsxindex fc10b184f7..5d5c846dae 100644--- a/apps/web/app/(ee)/app.dub.co/[slug]/(guide)/tracking-guide/page.tsx+++ b/apps/web/app/(ee)/app.dub.co/[slug]/(guide)/tracking-guide/page.tsx@@ -1,16 +1,15 @@+import { getIntegrationGuideMarkdown } from "@/lib/get-integration-guide-markdown";import { Guide } from "@/ui/guides/guide";import { GuideList } from "@/ui/guides/guide-list";import { guides, IntegrationGuide } from "@/ui/guides/integrations";-import { readFileSync } from "fs";import { notFound } from "next/navigation";-import { join } from "path";import { Suspense } from "react";export default async function Page({searchParams,}: {searchParams: {- guide: string;+ guide?: string;};}) {const { guide } = searchParams;@@ -25,7 +24,7 @@ export default async function Page({notFound();}- markdown = getMarkdown(selectedGuide.key);+ markdown = await getIntegrationGuideMarkdown(selectedGuide.key);if (!markdown) {notFound();@@ -52,18 +51,3 @@ export default async function Page({</Suspense>);}--function getMarkdown(guideKey: string): string | null {- const markdownPath = join(- process.cwd(),- "integration-guides",- `${guideKey}.md`,- );-- try {- return readFileSync(markdownPath, "utf-8");- } catch (error) {- console.warn(`Guide content not found for: ${guideKey}`);- return null;- }-}diff --git a/apps/web/lib/get-integration-guide-markdown.ts b/apps/web/lib/get-integration-guide-markdown.tsnew file mode 100644index 0000000000..6a684af374--- /dev/null+++ b/apps/web/lib/get-integration-guide-markdown.ts@@ -0,0 +1,32 @@+import { readFile } from "fs/promises";+import { join, normalize } from "path";++export async function getIntegrationGuideMarkdown(+ guideKey: string,+): Promise<string | null> {+ const sanitizedKey = guideKey.replace(/[^a-zA-Z0-9-_]/g, "");++ if (sanitizedKey !== guideKey) {+ return null;+ }++ const markdownPath = join(+ process.cwd(),+ "integration-guides",+ `${sanitizedKey}.md`,+ );++ // Additional security check: ensure the path is within the expected directory+ const normalizedPath = normalize(markdownPath);+ const expectedBase = normalize(join(process.cwd(), "integration-guides"));++ if (!normalizedPath.startsWith(expectedBase)) {+ return null;+ }++ try {+ return await readFile(normalizedPath, "utf-8");+ } catch (error) {+ return null;+ }+}