move beta access password out of .env into a data file

lets it be changed live without a redeploy/restart, and sidesteps
whatever was causing PROXY_PASSWORD not to reach process.env in prod
This commit is contained in:
first@lynx.com
2026-08-24 17:01:41 -04:00
parent a6ac6aaa4f
commit cc9fd16cf4
2 changed files with 18 additions and 6 deletions

View File

@ -9,4 +9,3 @@ NODE_ENV=production
DISCORD_AI_WEBHOOK=discord_webhook_url
PROCESSING_SERVER=https://git.ceres.rip/selenite/processing
PROCESSING_SERVER_SECRET=secret
PROXY_PASSWORD=change_me

View File

@ -18,6 +18,7 @@ import { callAI } from "./ai.js";
import { Readable } from 'stream';
import os from "node:os";
import crypto from "node:crypto";
import { readFileSync, existsSync } from "node:fs";
import { server as wisp, logging as wispLogging } from "@mercuryworkshop/wisp-js/server";
import { scramjetPath } from "@mercuryworkshop/scramjet/path";
import { libcurlPath } from "@mercuryworkshop/libcurl-transport";
@ -84,9 +85,20 @@ app.use(express.json({ limit: "10mb" }));
app.use(express.urlencoded({ extended: false }));
app.use(express.text());
const proxyPasswordPath = path.join(process.env.DATA_PATH, ".cache_meta");
function getProxyPassword() {
try {
if (!existsSync(proxyPasswordPath)) return null;
const value = readFileSync(proxyPasswordPath, "utf8").trim();
return value || null;
} catch {
return null;
}
}
function proxyUnlockToken() {
if (!process.env.PROXY_PASSWORD) return null;
return crypto.createHash("sha256").update(process.env.PROXY_PASSWORD).digest("hex");
const password = getProxyPassword();
if (!password) return null;
return crypto.createHash("sha256").update(password).digest("hex");
}
function isProxyUnlocked(req) {
const expected = proxyUnlockToken();
@ -101,11 +113,12 @@ function isProxyUnlockedRawCookieHeader(cookieHeader) {
return decodeURIComponent(match.slice("proxy_unlock=".length)) === expected;
}
app.post("/api/proxy/unlock", (req, res) => {
if (!process.env.PROXY_PASSWORD) {
const password = getProxyPassword();
if (!password) {
res.status(400).send({ success: false, message: "beta access is not configured." });
return;
}
if (req.body.password === process.env.PROXY_PASSWORD) {
if (req.body.password === password) {
res.cookie("proxy_unlock", proxyUnlockToken(), {
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24 * 365,