This commit is contained in:
Benjamin Toby 2026-02-02 13:35:10 +01:00
parent 24d9b1e1ac
commit 094273d853

View File

@ -8,6 +8,8 @@ type AdminPagesAuth = {
url?: string; url?: string;
}; };
const AuthExpiryTime = 1000 * 60 * 60;
const server = Bun.serve({ const server = Bun.serve({
port: AuthServerPort, port: AuthServerPort,
hostname: "0.0.0.0", hostname: "0.0.0.0",
@ -17,8 +19,6 @@ const server = Bun.serve({
try { try {
const reqURL = new URL(req.url); const reqURL = new URL(req.url);
console.log("reqURL", reqURL);
if (reqURL.pathname !== "/") { if (reqURL.pathname !== "/") {
return new Response("Auth Success!", { return new Response("Auth Success!", {
status: 200, status: 200,
@ -30,8 +30,6 @@ const server = Bun.serve({
const href = `https://${host}${query}`; const href = `https://${host}${query}`;
const url = new URL(href); const url = new URL(href);
console.log("url", url);
const key = url.searchParams.get("key"); const key = url.searchParams.get("key");
const decryptedKey = JSON.parse( const decryptedKey = JSON.parse(
@ -40,12 +38,20 @@ const server = Bun.serve({
const decrptedUrl = decryptedKey.url; const decrptedUrl = decryptedKey.url;
console.log("decrptedUrl", decrptedUrl);
if (!host || !decrptedUrl) { if (!host || !decrptedUrl) {
throw new Error(`Origin Not Found!`); throw new Error(`Origin Not Found!`);
} }
if (decrptedUrl !== host) {
throw new Error(`Host Mismatch!`);
}
const dateIssued = decryptedKey.date;
if (Date.now() - dateIssued > AuthExpiryTime) {
throw new Error(`Key Expired!`);
}
return new Response("Auth Success!", { return new Response("Auth Success!", {
status: 200, status: 200,
}); });