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;
};
const AuthExpiryTime = 1000 * 60 * 60;
const server = Bun.serve({
port: AuthServerPort,
hostname: "0.0.0.0",
@ -17,8 +19,6 @@ const server = Bun.serve({
try {
const reqURL = new URL(req.url);
console.log("reqURL", reqURL);
if (reqURL.pathname !== "/") {
return new Response("Auth Success!", {
status: 200,
@ -30,8 +30,6 @@ const server = Bun.serve({
const href = `https://${host}${query}`;
const url = new URL(href);
console.log("url", url);
const key = url.searchParams.get("key");
const decryptedKey = JSON.parse(
@ -40,12 +38,20 @@ const server = Bun.serve({
const decrptedUrl = decryptedKey.url;
console.log("decrptedUrl", decrptedUrl);
if (!host || !decrptedUrl) {
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!", {
status: 200,
});