Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: block certain paths on custom domains

Marc Seitzf7c94e494719
diff --git a/lib/constants.ts b/lib/constants.ts
index 20663582..b90e2165 100644
--- a/lib/constants.ts
+++ b/lib/constants.ts
@@ -35,3 +35,11 @@ export const REACTIONS = [
label: "down",
},
];
+
+// growing list of blocked pathnames that lead to 404s
+export const BLOCKED_PATHNAMES = [
+ "/phpmyadmin",
+ "/server-status",
+ "/wordpress",
+ "/_all_dbs",
+];
diff --git a/lib/middleware/domain.ts b/lib/middleware/domain.ts
index 4f77db57..520851b8 100644
--- a/lib/middleware/domain.ts
+++ b/lib/middleware/domain.ts
@@ -1,6 +1,5 @@
import { NextRequest, NextResponse } from "next/server";
-import { getToken } from "next-auth/jwt";
-import { PAPERMARK_HEADERS } from "../constants";
+import { BLOCKED_PATHNAMES, PAPERMARK_HEADERS } from "@/lib/constants";
export default async function DomainMiddleware(req: NextRequest) {
const path = req.nextUrl.pathname;
@@ -11,6 +10,10 @@ export default async function DomainMiddleware(req: NextRequest) {
// if there's a path and it's not "/" then we need to check if it's a custom domain
if (path !== "/") {
+ if (BLOCKED_PATHNAMES.includes(path) || path.includes(".")) {
+ url.pathname = "/404";
+ return NextResponse.rewrite(url);
+ }
// Subdomain available, rewriting
// >>> Rewriting: ${path} to /view/domains/${host}${path}`
url.pathname = `/view/domains/${host}${path}`;