feat(core): validate backup restores before mutation
Route selected backup entries through owner-owned config parsers before any filesystem write. Reject unsupported paths, mismatched encodings, malformed base64, lossy normalization, invalid effective overlays, and decoded payloads larger than 32 MiB. Treat WebUI state, private keys, and every OneBot config as a single sensitive group. Skip unselected sensitive entries without inspecting their contents, preserve recognized migrations, and assign restrictive modes to credential files.
This commit is contained in:
5 files changed
+1442
-86
No files matched your search
@@ -474,6 +474,11 @@ function imageStateFromParsed(parsed: unknown): ServerImageState {
|
||||
return sanitizeImageState(parsed.appearance.background);
|
||||
}
|
||||
|
||||
/** Normalize a complete ui.json read from disk or a backup bundle. */
|
||||
export function normalizeStoredUiConfig(value: unknown): UiConfig {
|
||||
return normalizeUiConfig(value, imageStateFromParsed(value));
|
||||
}
|
||||
|
||||
function normalizeBackground(value: unknown, imageState: ServerImageState): UiBackground {
|
||||
const v = isObject(value) ? value : {};
|
||||
let type = oneOf<BackgroundType>(v.type, ['none', 'solid', 'gradient', 'image'], DEFAULT_BACKGROUND.type);
|
||||
@@ -615,7 +620,7 @@ export function loadUiConfig(): UiConfig {
|
||||
const parsed = JSON.parse(raw) as unknown;
|
||||
// On load, the file itself is the source of truth for the server-managed
|
||||
// image fields — so they survive restarts (don't reset to defaults).
|
||||
const normalized = normalizeUiConfig(parsed, imageStateFromParsed(parsed));
|
||||
const normalized = normalizeStoredUiConfig(parsed);
|
||||
// Re-persist only if normalization changed something (corrupt/old file),
|
||||
// so we self-heal on disk without rewriting on every boot.
|
||||
if (JSON.stringify(parsed) !== JSON.stringify(normalized)) {
|
||||
|
||||
Reference in new issue
Block a user