settings sync: disallow possibly insecure settings

realistically this shouldn't matter too much, but still good to have
This commit is contained in:
Vendicated 2025-12-06 21:33:58 +01:00
parent 45ba135034
commit fa46c4c4d2
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18

View file

@ -24,6 +24,21 @@ const toastFailure = (err: any) =>
const logger = new Logger("SettingsSync:Offline", "#39b7e0");
function isSafeObject(obj: any) {
if (obj == null || typeof obj !== "object") return true;
for (const key in obj) {
if (["__proto__", "constructor", "prototype"].includes(key)) {
return false;
}
if (!isSafeObject(obj[key])) {
return false;
}
}
return true;
}
export async function importSettings(data: string) {
try {
var parsed = JSON.parse(data);
@ -32,6 +47,9 @@ export async function importSettings(data: string) {
throw new Error("Failed to parse JSON: " + String(err));
}
if (!isSafeObject(parsed))
throw new Error("Unsafe Settings");
if ("settings" in parsed && "quickCss" in parsed) {
Object.assign(PlainSettings, parsed.settings);
await VencordNative.settings.set(parsed.settings);