Audit the project and secure toolbox data

This commit is contained in:
Shinuwa 2026-10-14 16:59:09 +02:00
parent 96af62edf0
commit e87edda5c7
40 changed files with 2324 additions and 125 deletions

View file

@ -5,12 +5,12 @@ import {
createToolboxExportPayload,
globalModuleKey,
labelFromFileName,
MAX_TOOLBOX_SPACES,
normalizeToolbox,
remapMemosPlannerLink,
remapModuleOrderIds,
uid
} from "./storage/toolboxStorage.js";
import { validateToolboxImportPayload } from "./storage/toolboxImportValidation.js";
import { compressImage } from "../../utils/imageCompression.js";
import { getBackupFileName } from "./storage/autoBackup.js";
import { addModuleToToolboxSpace } from "./toolboxSpaceUtils.js";
@ -182,11 +182,7 @@ export function useToolboxActions({ store, notify, creationTemplate, setConfirmM
}
async function importToolboxPayload(file, gameId = "") {
const payload = JSON.parse(await file.text());
if (!payload.toolbox?.modules) throw new Error("Format d'outils invalide");
if (Array.isArray(payload.toolbox.spaces) && payload.toolbox.spaces.length > MAX_TOOLBOX_SPACES) {
throw new Error(`Une toolbox ne peut pas contenir plus de ${MAX_TOOLBOX_SPACES} espaces.`);
}
const payload = validateToolboxImportPayload(JSON.parse(await file.text()), "single");
const imported = normalizeToolbox({ ...payload.toolbox, id: uid("tbx"), updatedAt: new Date().toISOString() });
const moduleIdMap = new Map();
imported.modules = imported.modules.map((module) => {
@ -223,13 +219,7 @@ export function useToolboxActions({ store, notify, creationTemplate, setConfirmM
}
async function importAllToolboxesPayload(file) {
const payload = JSON.parse(await file.text());
if (!Array.isArray(payload.toolboxes) || !payload.modules || typeof payload.modules !== "object") {
throw new Error("Format d'import global invalide");
}
if (payload.toolboxes.some((toolbox) => Array.isArray(toolbox.spaces) && toolbox.spaces.length > MAX_TOOLBOX_SPACES)) {
throw new Error(`Une toolbox ne peut pas contenir plus de ${MAX_TOOLBOX_SPACES} espaces.`);
}
const payload = validateToolboxImportPayload(JSON.parse(await file.text()), "global");
const toolboxIdMap = new Map();
const moduleIdMap = new Map();
const importedToolboxes = payload.toolboxes.map((toolbox) => {