security: sign key-feed requests with a timestamped HMAC
This commit is contained in:
1 parent
05fc55e941
commit
c8b1b7027c
1 file changed
+12
-3
+12
-3
@@ -31,6 +31,7 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
const crypto = require("crypto");
|
||||||
|
|
||||||
// --- env assembly: exec sessions lack the app's process env ---------------
|
// --- env assembly: exec sessions lack the app's process env ---------------
|
||||||
function loadEnvFile(p) {
|
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 MONGO_URL = process.env.CLOUDRON_MONGODB_URL || process.env.MONGODB_URL;
|
||||||
const PORTAL_URL = process.env.PORTAL_URL || "https://portal.inference.coop";
|
const PORTAL_URL = process.env.PORTAL_URL || "https://portal.inference.coop";
|
||||||
const SYNC_TOKEN = process.env.LIBRECHAT_SYNC_TOKEN || "";
|
const SYNC_TOKEN = process.env.LIBRECHAT_SYNC_TOKEN || "";
|
||||||
|
const SYNC_HMAC_SECRET = process.env.KEY_FEED_HMAC_SECRET || "";
|
||||||
const ENDPOINT_NAME = "Inference Co-op";
|
const ENDPOINT_NAME = "Inference Co-op";
|
||||||
|
|
||||||
// Which revision is actually running? The script lives on the persistent volume,
|
// 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 () => {
|
(async () => {
|
||||||
// 1. Fetch active members' chat keys from the portal (dedicated sync token)
|
// 1. Fetch active members' chat keys from the portal (dedicated sync token)
|
||||||
const res = await fetch(`${PORTAL_URL}/admin/librechat/keys`, {
|
const headers = { "X-Sync-Token": SYNC_TOKEN };
|
||||||
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) {
|
if (!res.ok) {
|
||||||
console.error(`FATAL: portal key feed returned ${res.status}`);
|
console.error(`FATAL: portal key feed returned ${res.status}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|||||||
Reference in new issue
Block a user