Skip to content

Commit 8977141

Browse files
authored
Prevent Login iFrame (#684)
* Update middleware.ts * Update middleware.ts
1 parent ca8315b commit 8977141

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

apps/web/middleware.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { db } from "@cap/database";
22
import { organizations } from "@cap/database/schema";
3-
import { eq } from "drizzle-orm";
43
import { buildEnv, serverEnv } from "@cap/env";
4+
import { eq } from "drizzle-orm";
55
import { notFound } from "next/navigation";
66
import { NextRequest, NextResponse, userAgent } from "next/server";
77

@@ -22,9 +22,21 @@ const mainOrigins = [
2222

2323
export async function middleware(request: NextRequest) {
2424
const url = new URL(request.url);
25-
const hostname = url.hostname;
2625
const path = url.pathname;
2726

27+
// Add anti-clickjacking headers for /login
28+
if (path.startsWith("/login")) {
29+
const response = NextResponse.next();
30+
response.headers.set("X-Frame-Options", "SAMEORIGIN");
31+
response.headers.set(
32+
"Content-Security-Policy",
33+
"frame-ancestors https://cap.so"
34+
);
35+
return response;
36+
}
37+
38+
const hostname = url.hostname;
39+
2840
if (buildEnv.NEXT_PUBLIC_IS_CAP !== "true") {
2941
if (
3042
!(

0 commit comments

Comments
 (0)