Skip to content

Commit

Permalink
web(arcane-nebula): xff
Browse files Browse the repository at this point in the history
  • Loading branch information
kgeorgiou committed Apr 29, 2024
1 parent 2b4fb2a commit e61aaff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
21 changes: 8 additions & 13 deletions web/arcane-nebula/setup/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@ const server = Bun.serve({
return new Response(Bun.file(import.meta.dir + index));
}

if (url.pathname.endsWith("/ip-test-091827")) {
const ip1 = server.requestIP(req)?.address;
const xff = req.headers.get("x-forwarded-for");

const ss = `
server.requestIP(req) -> ${ip1}
xff -> ${xff}
`;
return new Response(ss);
}

if (url.pathname.endsWith("/spell")) {
const reqIP = server.requestIP(req);
const xff = req.headers
.get("x-forwarded-for")
?.split(",")
.map((x) => x.trim());

const reqIP = xff ? xff[xff?.length - 1] : server.requestIP(req)?.address;

const allowed = [
"103.21.244.0/22",
"103.22.200.0/22",
Expand All @@ -48,7 +43,7 @@ xff -> ${xff}
].map((s) => new Netmask(s));

try {
if (allowed.some((a) => a.contains(reqIP?.address ?? ""))) {
if (allowed.some((a) => a.contains(reqIP ?? ""))) {
const spell = "/views/spell.html";
return new Response(Bun.file(import.meta.dir + spell));
}
Expand Down
12 changes: 10 additions & 2 deletions web/arcane-nebula/setup/app/views/denied.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@
}

if (url.pathname.endsWith("/spell")) {
const reqIP = server.requestIP(req);
const xff = req.headers
.get("x-forwarded-for")
?.split(",")
.map((x) => x.trim());

const reqIP = xff ? xff[xff?.length - 1] : server.requestIP(req)?.address;

const allowed = [
"103.21.244.0/22",
"103.22.200.0/22",
"103.31.4.0/22",
"104.16.0.0/12",
"104.16.0.0/13",
"104.24.0.0/14",
"104.28.0.0/14",
"108.162.192.0/18",
"131.0.72.0/22",
"141.101.64.0/18",
Expand All @@ -53,7 +61,7 @@
].map((s) => new Netmask(s));

try {
if (allowed.some((a) => a.contains(reqIP?.address ?? ""))) {
if (allowed.some((a) => a.contains(reqIP ?? ""))) {
const spell = "/views/spell.html";
return new Response(Bun.file(import.meta.dir + spell));
}
Expand Down

0 comments on commit e61aaff

Please sign in to comment.