Skip to content

Commit

Permalink
middleware to prevent path traversal attempts (#9554)
Browse files Browse the repository at this point in the history
  • Loading branch information
spolu authored Dec 20, 2024
1 parent 7d5808f commit 9f7e42d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions front/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";

export function middleware(request: NextRequest) {
// Detect path traversal attempts
const url = request.nextUrl.pathname;
if (url.includes("../") || url.includes("..%2F") || url.includes("..%5C")) {
return new NextResponse(null, { status: 400 });
}

return NextResponse.next();
}

export const config = {
matcher: "/:path*",
};

0 comments on commit 9f7e42d

Please sign in to comment.