This commit is contained in:
1 parent
8efd032cc6
commit
df38dccbf1
735 files changed
+128321
-120870
No files matched your search
+26
-24
@@ -1,40 +1,42 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { proxyAuth } from "@/lib/proxy-auth";
|
||||
import { shouldRedirectAdminRequest } from "@/lib/proxy-access";
|
||||
import { proxyAuth } from "@/lib/proxy-auth";
|
||||
|
||||
const SECURITY_HEADERS: Record<string, string> = {
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
"X-Frame-Options": "DENY",
|
||||
"X-XSS-Protection": "0",
|
||||
"Referrer-Policy": "strict-origin-when-cross-origin",
|
||||
"Permissions-Policy": "camera=(), microphone=(), geolocation=()",
|
||||
"Strict-Transport-Security": "max-age=63072000; includeSubDomains; preload",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
"X-Frame-Options": "DENY",
|
||||
"X-XSS-Protection": "0",
|
||||
"Referrer-Policy": "strict-origin-when-cross-origin",
|
||||
"Permissions-Policy": "camera=(), microphone=(), geolocation=()",
|
||||
"Strict-Transport-Security": "max-age=63072000; includeSubDomains; preload",
|
||||
};
|
||||
|
||||
export const proxy = proxyAuth((req) => {
|
||||
if (shouldRedirectAdminRequest(req.nextUrl.pathname, req.auth?.user ?? null)) {
|
||||
return NextResponse.redirect(new URL("/login", req.url));
|
||||
}
|
||||
if (
|
||||
shouldRedirectAdminRequest(req.nextUrl.pathname, req.auth?.user ?? null)
|
||||
) {
|
||||
return NextResponse.redirect(new URL("/login", req.url));
|
||||
}
|
||||
|
||||
const headers = new Headers(req.headers);
|
||||
headers.set("x-pathname", req.nextUrl.pathname);
|
||||
const headers = new Headers(req.headers);
|
||||
headers.set("x-pathname", req.nextUrl.pathname);
|
||||
|
||||
const ip =
|
||||
req.headers.get("cf-connecting-ip") ??
|
||||
req.headers.get("x-forwarded-for")?.split(",")[0]?.trim() ??
|
||||
req.headers.get("x-real-ip") ??
|
||||
"";
|
||||
if (ip) headers.set("x-real-client-ip", ip);
|
||||
const ip =
|
||||
req.headers.get("cf-connecting-ip") ??
|
||||
req.headers.get("x-forwarded-for")?.split(",")[0]?.trim() ??
|
||||
req.headers.get("x-real-ip") ??
|
||||
"";
|
||||
if (ip) headers.set("x-real-client-ip", ip);
|
||||
|
||||
const response = NextResponse.next({ request: { headers } });
|
||||
const response = NextResponse.next({ request: { headers } });
|
||||
|
||||
for (const [key, value] of Object.entries(SECURITY_HEADERS)) {
|
||||
response.headers.set(key, value);
|
||||
}
|
||||
for (const [key, value] of Object.entries(SECURITY_HEADERS)) {
|
||||
response.headers.set(key, value);
|
||||
}
|
||||
|
||||
return response;
|
||||
return response;
|
||||
});
|
||||
|
||||
export const config = {
|
||||
matcher: ["/((?!api|_next/static|_next/image|assets|favicon.ico).*)"],
|
||||
matcher: ["/((?!api|_next/static|_next/image|assets|favicon.ico).*)"],
|
||||
};
|
||||
Reference in new issue
Block a user