Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
Revert "chore: add trpc source guard"
Maximilian Kaske86c2781a3e2c
diff --git a/apps/dashboard/src/app/api/trpc/edge/[trpc]/route.ts b/apps/dashboard/src/app/api/trpc/edge/[trpc]/route.tsindex 078d4c4d8..ee69b118c 100644--- a/apps/dashboard/src/app/api/trpc/edge/[trpc]/route.ts+++ b/apps/dashboard/src/app/api/trpc/edge/[trpc]/route.ts@@ -2,17 +2,13 @@ import { fetchRequestHandler } from "@trpc/server/adapters/fetch";import type { NextRequest } from "next/server";import { auth } from "@/lib/auth";-import { guardTRPCSource } from "@/lib/trpc/shared";import { createTRPCContext } from "@openstatus/api";import { edgeRouter } from "@openstatus/api/src/edge";export const runtime = "edge";-const handler = (req: NextRequest) => {- const blocked = guardTRPCSource(req);- if (blocked) return blocked;-- return fetchRequestHandler({+const handler = (req: NextRequest) =>+ fetchRequestHandler({endpoint: "/api/trpc/edge",router: edgeRouter,req: req,@@ -22,6 +18,5 @@ const handler = (req: NextRequest) => {console.error(error);},});-};export { handler as GET, handler as POST };diff --git a/apps/dashboard/src/app/api/trpc/lambda/[trpc]/route.ts b/apps/dashboard/src/app/api/trpc/lambda/[trpc]/route.tsindex 3192adb41..1352dcf0c 100644--- a/apps/dashboard/src/app/api/trpc/lambda/[trpc]/route.ts+++ b/apps/dashboard/src/app/api/trpc/lambda/[trpc]/route.ts@@ -2,18 +2,14 @@ import { fetchRequestHandler } from "@trpc/server/adapters/fetch";import type { NextRequest } from "next/server";import { auth } from "@/lib/auth";-import { guardTRPCSource } from "@/lib/trpc/shared";import { createTRPCContext } from "@openstatus/api";import { lambdaRouter } from "@openstatus/api/src/lambda";// Stripe is incompatible with Edge runtimes due to using Node.js events// export const runtime = "edge";-const handler = (req: NextRequest) => {- const blocked = guardTRPCSource(req);- if (blocked) return blocked;-- return fetchRequestHandler({+const handler = (req: NextRequest) =>+ fetchRequestHandler({endpoint: "/api/trpc/lambda",router: lambdaRouter,req: req,@@ -23,6 +19,5 @@ const handler = (req: NextRequest) => {console.error(error);},});-};export { handler as GET, handler as POST };diff --git a/apps/dashboard/src/lib/trpc/shared.ts b/apps/dashboard/src/lib/trpc/shared.tsindex 74a88d12d..23af94147 100644--- a/apps/dashboard/src/lib/trpc/shared.ts+++ b/apps/dashboard/src/lib/trpc/shared.ts@@ -4,19 +4,6 @@ import { httpBatchLink } from "@trpc/client";import type { AppRouter } from "@openstatus/api";import superjson from "superjson";-/**- * Reject requests that don't come from our tRPC clients.- * Our server and client links always set `x-trpc-source`.- * Returns a 401 Response if the header is missing, or null if valid.- */-export function guardTRPCSource(req: Request): Response | null {- const source = req.headers.get("x-trpc-source");- if (source !== "server" && source !== "client") {- return new Response(null, { status: 401 });- }- return null;-}-const getBaseUrl = () => {if (typeof window !== "undefined") return "";// Note: dashboard has its own tRPC API routesdiff --git a/apps/status-page/src/app/api/trpc/edge/[trpc]/route.ts b/apps/status-page/src/app/api/trpc/edge/[trpc]/route.tsindex a30251986..cf4f2382b 100644--- a/apps/status-page/src/app/api/trpc/edge/[trpc]/route.ts+++ b/apps/status-page/src/app/api/trpc/edge/[trpc]/route.ts@@ -2,23 +2,19 @@ import { fetchRequestHandler } from "@trpc/server/adapters/fetch";import type { NextRequest } from "next/server";import { auth } from "@/lib/auth";-import { createOnError, guardTRPCSource } from "@/lib/trpc/shared";+import { createOnError } from "@/lib/trpc/shared";import { createTRPCContext } from "@openstatus/api";import { edgeRouter } from "@openstatus/api/src/edge";export const runtime = "edge";-const handler = (req: NextRequest) => {- const blocked = guardTRPCSource(req);- if (blocked) return blocked;-- return fetchRequestHandler({+const handler = (req: NextRequest) =>+ fetchRequestHandler({endpoint: "/api/trpc/edge",router: edgeRouter,req: req,createContext: () => createTRPCContext({ req, auth }),onError: createOnError(req, "edge"),});-};export { handler as GET, handler as POST };diff --git a/apps/status-page/src/app/api/trpc/lambda/[trpc]/route.ts b/apps/status-page/src/app/api/trpc/lambda/[trpc]/route.tsindex be9db45d2..416a78262 100644--- a/apps/status-page/src/app/api/trpc/lambda/[trpc]/route.ts+++ b/apps/status-page/src/app/api/trpc/lambda/[trpc]/route.ts@@ -2,24 +2,20 @@ import { fetchRequestHandler } from "@trpc/server/adapters/fetch";import type { NextRequest } from "next/server";import { auth } from "@/lib/auth";-import { createOnError, guardTRPCSource } from "@/lib/trpc/shared";+import { createOnError } from "@/lib/trpc/shared";import { createTRPCContext } from "@openstatus/api";import { lambdaRouter } from "@openstatus/api/src/lambda";// Stripe is incompatible with Edge runtimes due to using Node.js events// export const runtime = "edge";-const handler = (req: NextRequest) => {- const blocked = guardTRPCSource(req);- if (blocked) return blocked;-- return fetchRequestHandler({+const handler = (req: NextRequest) =>+ fetchRequestHandler({endpoint: "/api/trpc/lambda",router: lambdaRouter,req: req,createContext: () => createTRPCContext({ req, auth }),onError: createOnError(req, "lambda"),});-};export { handler as GET, handler as POST };diff --git a/apps/status-page/src/lib/trpc/shared.ts b/apps/status-page/src/lib/trpc/shared.tsindex a70309aad..c5dd92c2f 100644--- a/apps/status-page/src/lib/trpc/shared.ts+++ b/apps/status-page/src/lib/trpc/shared.ts@@ -23,19 +23,6 @@ export function createOnError(req: Request, label: string) {};}-/**- * Reject requests that don't come from our tRPC clients.- * Our server and client links always set `x-trpc-source`.- * Returns a 401 Response if the header is missing, or null if valid.- */-export function guardTRPCSource(req: Request): Response | null {- const source = req.headers.get("x-trpc-source");- if (source !== "server" && source !== "client") {- return new Response(null, { status: 401 });- }- return null;-}-const getBaseUrl = () => {if (typeof window !== "undefined") return "";// Note: status-page has its own tRPC API routesdiff --git a/apps/web/src/app/api/trpc/edge/[trpc]/route.ts b/apps/web/src/app/api/trpc/edge/[trpc]/route.tsindex 65f784175..2c1fc5285 100644--- a/apps/web/src/app/api/trpc/edge/[trpc]/route.ts+++ b/apps/web/src/app/api/trpc/edge/[trpc]/route.ts@@ -1,17 +1,13 @@import { fetchRequestHandler } from "@trpc/server/adapters/fetch";import type { NextRequest } from "next/server";-import { guardTRPCSource } from "@/trpc/shared";import { createTRPCContext } from "@openstatus/api";import { edgeRouter } from "@openstatus/api/src/edge";export const runtime = "edge";-const handler = (req: NextRequest) => {- const blocked = guardTRPCSource(req);- if (blocked) return blocked;-- return fetchRequestHandler({+const handler = (req: NextRequest) =>+ fetchRequestHandler({endpoint: "/api/trpc/edge",router: edgeRouter,req: req,@@ -21,6 +17,5 @@ const handler = (req: NextRequest) => {console.error(error);},});-};export { handler as GET, handler as POST };diff --git a/apps/web/src/app/api/trpc/lambda/[trpc]/route.ts b/apps/web/src/app/api/trpc/lambda/[trpc]/route.tsindex 9a75341be..b36568088 100644--- a/apps/web/src/app/api/trpc/lambda/[trpc]/route.ts+++ b/apps/web/src/app/api/trpc/lambda/[trpc]/route.ts@@ -1,18 +1,14 @@import { fetchRequestHandler } from "@trpc/server/adapters/fetch";import type { NextRequest } from "next/server";-import { guardTRPCSource } from "@/trpc/shared";import { createTRPCContext } from "@openstatus/api";import { lambdaRouter } from "@openstatus/api/src/lambda";// Stripe is incompatible with Edge runtimes due to using Node.js events// export const runtime = "edge";-const handler = (req: NextRequest) => {- const blocked = guardTRPCSource(req);- if (blocked) return blocked;-- return fetchRequestHandler({+const handler = (req: NextRequest) =>+ fetchRequestHandler({endpoint: "/api/trpc/lambda",router: lambdaRouter,req: req,@@ -22,6 +18,5 @@ const handler = (req: NextRequest) => {console.error(error);},});-};export { handler as GET, handler as POST };diff --git a/apps/web/src/trpc/shared.ts b/apps/web/src/trpc/shared.tsindex 5d3dcd6e9..d6c8c89c2 100644--- a/apps/web/src/trpc/shared.ts+++ b/apps/web/src/trpc/shared.ts@@ -4,19 +4,6 @@ import { httpBatchLink } from "@trpc/client";import type { AppRouter } from "@openstatus/api";import superjson from "superjson";-/**- * Reject requests that don't come from our tRPC clients.- * Our server and client links always set `x-trpc-source`.- * Returns a 401 Response if the header is missing, or null if valid.- */-export function guardTRPCSource(req: Request): Response | null {- const source = req.headers.get("x-trpc-source");- if (source !== "server" && source !== "client") {- return new Response(null, { status: 401 });- }- return null;-}-const getBaseUrl = () => {if (typeof window !== "undefined") return "";if (process.env.VERCEL_ENV === "production")diff --git a/packages/api/src/trpc.ts b/packages/api/src/trpc.tsindex ba5401d6d..db7b1dc03 100644--- a/packages/api/src/trpc.ts+++ b/packages/api/src/trpc.ts@@ -73,6 +73,18 @@ export const createTRPCContext = async (opts: {}) => {// Use provided auth function or return null sessionconst session = opts.auth ? await opts.auth() : null;++ console.log("[createTRPCContext debug]", {+ hasAuthFn: !!opts.auth,+ sessionResult: session ? "exists" : "null",+ hasReq: !!opts.req,+ hasCookie: !!opts.req?.headers.get("cookie"),+ hasSessionToken:+ !!opts.req?.cookies.get("authjs.session-token")?.value ||+ !!opts.req?.cookies.get("__Secure-authjs.session-token")?.value,+ userAgent: opts.req?.headers.get("user-agent"),+ });+const workspace = null;const user = null;