Compare commits
5 Commits
32758f32d3
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| fcf8c805f6 | |||
| ea5d1744a7 | |||
| 7fe713e299 | |||
| 5502415825 | |||
| 85f2b99345 |
@@ -2,4 +2,5 @@ NEXT_PUBLIC_ENV=prod
|
|||||||
NEXT_PUBLIC_API_BASE=https://test-kfpa-dash.kric.com/api
|
NEXT_PUBLIC_API_BASE=https://test-kfpa-dash.kric.com/api
|
||||||
|
|
||||||
ENV=prod
|
ENV=prod
|
||||||
API_BACK_SERVER=http://127.0.0.1:6103/api/v1
|
API_BACK_SERVER=http://127.0.0.1:6103/api/v1
|
||||||
|
IP_WHITELIST=127.0.0.1,::1,211.37.10.198,211.254.145.130,1.235.195.3
|
||||||
@@ -2,4 +2,5 @@ NEXT_PUBLIC_ENV=local
|
|||||||
NEXT_PUBLIC_API_BASE=http://localhost:6102/api
|
NEXT_PUBLIC_API_BASE=http://localhost:6102/api
|
||||||
|
|
||||||
ENV=local
|
ENV=local
|
||||||
API_BACK_SERVER=http://localhost:6103/api/v1
|
API_BACK_SERVER=http://localhost:6103/api/v1
|
||||||
|
IP_WHITELIST=127.0.0.1,::1
|
||||||
@@ -2,4 +2,5 @@ NEXT_PUBLIC_ENV=prod
|
|||||||
NEXT_PUBLIC_API_BASE=https://kfpa-dash.kric.com/api
|
NEXT_PUBLIC_API_BASE=https://kfpa-dash.kric.com/api
|
||||||
|
|
||||||
ENV=prod
|
ENV=prod
|
||||||
API_BACK_SERVER=http://127.0.0.1:6103/api/v1
|
API_BACK_SERVER=http://127.0.0.1:6103/api/v1
|
||||||
|
IP_WHITELIST=127.0.0.1,::1,211.37.10.198,211.254.145.130,1.235.195.3
|
||||||
21
src/app/403/page.tsx
Normal file
21
src/app/403/page.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import type { Metadata } from "next";
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "403 Forbidden",
|
||||||
|
};
|
||||||
|
|
||||||
|
const ForbiddenPage = () => {
|
||||||
|
return (
|
||||||
|
<main className="flex min-h-dvh items-center justify-center bg-background px-6">
|
||||||
|
<section className="w-full max-w-md border border-border bg-card p-8 text-center shadow-sm">
|
||||||
|
<p className="text-sm font-semibold text-primary">403</p>
|
||||||
|
<h1 className="mt-3 text-2xl font-bold text-foreground">외부에서 접속할 수 없습니다.</h1>
|
||||||
|
<p className="mt-4 text-sm leading-6 text-muted-foreground">
|
||||||
|
해당 사이트는 외부의 접근을 허용하지 않습니다.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ForbiddenPage;
|
||||||
@@ -225,7 +225,7 @@ const CustomerSatisfactionTotal = () => {
|
|||||||
valueFormatter={(value) => value.toFixed(2)}
|
valueFormatter={(value) => value.toFixed(2)}
|
||||||
barMaxWidth={30}
|
barMaxWidth={30}
|
||||||
showFocusLabel="all"
|
showFocusLabel="all"
|
||||||
labelOptions={{ position: "top", distance: 4 }}
|
labelOptions={{ position: "top", distance: 4 , minPositionValue: 3.99}}
|
||||||
grid={{ left: 0, right: 0, top: 30, bottom: 5 }}
|
grid={{ left: 0, right: 0, top: 30, bottom: 5 }}
|
||||||
xAxis={{
|
xAxis={{
|
||||||
type: "category",
|
type: "category",
|
||||||
|
|||||||
111
src/proxy.ts
Normal file
111
src/proxy.ts
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
|
const IP_WHITELIST_ENV = "IP_WHITELIST";
|
||||||
|
const LOCAL_IPS = new Set(["127.0.0.1", "::1"]);
|
||||||
|
|
||||||
|
const normalizeIp = (ip: string) => {
|
||||||
|
const trimmed = ip.trim();
|
||||||
|
|
||||||
|
if (!trimmed) return "";
|
||||||
|
if (trimmed.startsWith("::ffff:")) return trimmed.slice("::ffff:".length);
|
||||||
|
|
||||||
|
const withoutBrackets = trimmed.replace(/^\[|\]$/g, "");
|
||||||
|
const portSeparatorIndex = withoutBrackets.lastIndexOf(":");
|
||||||
|
if (
|
||||||
|
portSeparatorIndex > -1 &&
|
||||||
|
withoutBrackets.indexOf(":") === portSeparatorIndex &&
|
||||||
|
/^\d+$/.test(withoutBrackets.slice(portSeparatorIndex + 1))
|
||||||
|
) {
|
||||||
|
return withoutBrackets.slice(0, portSeparatorIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return withoutBrackets;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getClientIp = (request: NextRequest) => {
|
||||||
|
const forwardedFor = request.headers.get("x-forwarded-for");
|
||||||
|
if (forwardedFor) {
|
||||||
|
return normalizeIp(forwardedFor.split(",")[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return normalizeIp(
|
||||||
|
request.headers.get("x-real-ip") ??
|
||||||
|
request.headers.get("cf-connecting-ip") ??
|
||||||
|
request.headers.get("true-client-ip") ??
|
||||||
|
""
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const ipv4ToNumber = (ip: string) => {
|
||||||
|
const parts = ip.split(".");
|
||||||
|
if (parts.length !== 4) return null;
|
||||||
|
|
||||||
|
return parts.reduce<number | null>((acc, part) => {
|
||||||
|
if (acc === null || !/^\d+$/.test(part)) return null;
|
||||||
|
|
||||||
|
const value = Number(part);
|
||||||
|
if (value < 0 || value > 255) return null;
|
||||||
|
|
||||||
|
return ((acc << 8) + value) >>> 0;
|
||||||
|
}, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isIpv4InCidr = (ip: string, cidr: string) => {
|
||||||
|
const [rangeIp, prefixRaw] = cidr.split("/");
|
||||||
|
const prefix = Number(prefixRaw);
|
||||||
|
const target = ipv4ToNumber(ip);
|
||||||
|
const range = ipv4ToNumber(rangeIp);
|
||||||
|
|
||||||
|
if (target === null || range === null || !Number.isInteger(prefix) || prefix < 0 || prefix > 32) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mask = prefix === 0 ? 0 : (0xffffffff << (32 - prefix)) >>> 0;
|
||||||
|
return (target & mask) === (range & mask);
|
||||||
|
};
|
||||||
|
|
||||||
|
const parseWhitelist = () =>
|
||||||
|
(process.env[IP_WHITELIST_ENV] ?? "")
|
||||||
|
.split(",")
|
||||||
|
.map((ip) => normalizeIp(ip))
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
const isAllowedIp = (clientIp: string) => {
|
||||||
|
const whitelist = parseWhitelist();
|
||||||
|
|
||||||
|
if (whitelist.length === 0) {
|
||||||
|
return process.env.ENV === "local" && LOCAL_IPS.has(clientIp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return whitelist.some((allowedIp) => {
|
||||||
|
if (allowedIp.includes("/")) {
|
||||||
|
return isIpv4InCidr(clientIp, allowedIp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return clientIp === allowedIp;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export function proxy(request: NextRequest) {
|
||||||
|
const pathname = request.nextUrl.pathname;
|
||||||
|
|
||||||
|
if (pathname === "/403") {
|
||||||
|
return NextResponse.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
const clientIp = getClientIp(request);
|
||||||
|
|
||||||
|
if (clientIp && isAllowedIp(clientIp)) {
|
||||||
|
return NextResponse.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = request.nextUrl.clone();
|
||||||
|
url.pathname = "/403";
|
||||||
|
url.search = "";
|
||||||
|
|
||||||
|
return NextResponse.redirect(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const config = {
|
||||||
|
matcher: ["/((?!api|_next/static|_next/image|favicon.ico|.*\\..*).*)"],
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user