SECURITY - LAUNCHER: harden storage and access lifecycle
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import { mkdir, rename, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { isAbsolute, join, resolve } from "node:path";
|
||||
|
||||
const collectionKeys = [
|
||||
"clients",
|
||||
@@ -62,16 +62,18 @@ const defaultSettings = {
|
||||
};
|
||||
|
||||
export function createControlPlaneStore({ projectRoot }) {
|
||||
const publicStorageRoot = join(projectRoot, "public", "storage");
|
||||
const distStorageRoot = join(projectRoot, "dist", "storage");
|
||||
const dataPath = join(publicStorageRoot, "launcher-data.json");
|
||||
const serverStorageRoot = resolveStorageRoot(projectRoot);
|
||||
const legacyPublicDataPath = join(projectRoot, "public", "storage", "launcher-data.json");
|
||||
const dataPath = join(serverStorageRoot, "launcher-data.json");
|
||||
|
||||
function readData() {
|
||||
if (!existsSync(dataPath)) {
|
||||
const readablePath = existsSync(dataPath) ? dataPath : legacyPublicDataPath;
|
||||
|
||||
if (!existsSync(readablePath)) {
|
||||
return normalizeData({});
|
||||
}
|
||||
|
||||
return normalizeData(JSON.parse(readFileSync(dataPath, "utf8")));
|
||||
return normalizeData(JSON.parse(readFileSync(readablePath, "utf8")));
|
||||
}
|
||||
|
||||
async function writeData(data) {
|
||||
@@ -1192,6 +1194,10 @@ export function createControlPlaneStore({ projectRoot }) {
|
||||
throw new Error("Этот инвайт выписан на другую почту");
|
||||
}
|
||||
|
||||
if (invite.status === "accepted") {
|
||||
throw new Error("Инвайт уже принят");
|
||||
}
|
||||
|
||||
if (invite.status === "revoked") {
|
||||
throw new Error("Инвайт отозван");
|
||||
}
|
||||
@@ -1711,13 +1717,7 @@ export function createControlPlaneStore({ projectRoot }) {
|
||||
}
|
||||
|
||||
function getWritableStorageRoots() {
|
||||
const roots = [publicStorageRoot];
|
||||
|
||||
if (existsSync(join(projectRoot, "dist"))) {
|
||||
roots.push(distStorageRoot);
|
||||
}
|
||||
|
||||
return roots;
|
||||
return [serverStorageRoot];
|
||||
}
|
||||
|
||||
function getLoginAccountStatus(email) {
|
||||
@@ -1799,6 +1799,16 @@ export function createControlPlaneStore({ projectRoot }) {
|
||||
};
|
||||
}
|
||||
|
||||
function resolveStorageRoot(projectRoot) {
|
||||
const configuredRoot = process.env.NODEDC_LAUNCHER_STORAGE_DIR;
|
||||
|
||||
if (configuredRoot && configuredRoot.trim()) {
|
||||
return isAbsolute(configuredRoot) ? configuredRoot : resolve(projectRoot, configuredRoot);
|
||||
}
|
||||
|
||||
return join(projectRoot, "server", "storage");
|
||||
}
|
||||
|
||||
function normalizeData(payload) {
|
||||
const data = typeof payload === "object" && payload !== null ? { ...payload } : {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user