security: sign key-feed requests with a timestamped HMAC

This commit is contained in:
inference-admin committed 2026-11-20 00:18:44 +00:00
1 parent 05fc55e941
commit c8b1b7027c
1 file changed
+12 -3
+12 -3
View File
@@ -31,6 +31,7 @@
const fs = require("fs");
const os = require("os");
const path = require("path");
const crypto = require("crypto");
// --- env assembly: exec sessions lack the app's process env ---------------
function loadEnvFile(p) {
@@ -52,6 +53,7 @@ try { // CREDS_KEY / CREDS_IV / MONGODB live in the app process env
const MONGO_URL = process.env.CLOUDRON_MONGODB_URL || process.env.MONGODB_URL;
const PORTAL_URL = process.env.PORTAL_URL || "https://portal.inference.coop";
const SYNC_TOKEN = process.env.LIBRECHAT_SYNC_TOKEN || "";
const SYNC_HMAC_SECRET = process.env.KEY_FEED_HMAC_SECRET || "";
const ENDPOINT_NAME = "Inference Co-op";
// Which revision is actually running? The script lives on the persistent volume,
@@ -103,9 +105,16 @@ const mongoose = require("/app/code/librechat/node_modules/mongoose");
(async () => {
// 1. Fetch active members' chat keys from the portal (dedicated sync token)
const res = await fetch(`${PORTAL_URL}/admin/librechat/keys`, {
headers: { "X-Sync-Token": SYNC_TOKEN },
});
const headers = { "X-Sync-Token": SYNC_TOKEN };
if (SYNC_HMAC_SECRET) {
const ts = String(Math.floor(Date.now() / 1000));
headers["X-Sync-Timestamp"] = ts;
headers["X-Sync-Signature"] = crypto
.createHmac("sha256", SYNC_HMAC_SECRET)
.update(`${ts}\n/admin/librechat/keys\n`)
.digest("hex");
}
const res = await fetch(`${PORTAL_URL}/admin/librechat/keys`, { headers });
if (!res.ok) {
console.error(`FATAL: portal key feed returned ${res.status}`);
process.exit(1);