Skip to content

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

chore: catch blocked pathnames on regular domains

Marc Seitz355ade09b56d
diff --git a/lib/middleware/domain.ts b/lib/middleware/domain.ts
index 520851b8..4bd11bfd 100644
--- a/lib/middleware/domain.ts
+++ b/lib/middleware/domain.ts
@@ -12,7 +12,7 @@ export default async function DomainMiddleware(req: NextRequest) {
if (path !== "/") {
if (BLOCKED_PATHNAMES.includes(path) || path.includes(".")) {
url.pathname = "/404";
- return NextResponse.rewrite(url);
+ return NextResponse.rewrite(url, { status: 404 });
}
// Subdomain available, rewriting
// >>> Rewriting: ${path} to /view/domains/${host}${path}`
diff --git a/middleware.ts b/middleware.ts
index 30a01912..e491e8aa 100644
--- a/middleware.ts
+++ b/middleware.ts
@@ -1,6 +1,7 @@
import { NextFetchEvent, NextRequest, NextResponse } from "next/server";
import AppMiddleware from "@/lib/middleware/app";
import DomainMiddleware from "@/lib/middleware/domain";
+import { BLOCKED_PATHNAMES } from "./lib/constants";
export const config = {
matcher: [
@@ -55,5 +56,16 @@ export default async function middleware(req: NextRequest, ev: NextFetchEvent) {
return AppMiddleware(req);
}
+ const url = req.nextUrl.clone();
+
+ if (
+ path.startsWith("/view/") &&
+ (BLOCKED_PATHNAMES.some((blockedPath) => path.includes(blockedPath)) ||
+ path.includes("."))
+ ) {
+ url.pathname = "/404";
+ return NextResponse.rewrite(url, { status: 404 });
+ }
+
return NextResponse.next();
}