"fix: resolved UI combo setting schema strip (#458)"

"fix: safe crypto fallback for MITM on windows (#456)"
This commit is contained in:
diegosouzapw
2026-03-18 17:16:30 -03:00
parent 8420e565d4
commit eaf4a5805c
2 changed files with 30 additions and 15 deletions

View File

@@ -23,13 +23,16 @@ export async function getConsistentMachineId(salt = null) {
} catch (error) {
console.log("Error getting machine ID:", error);
// Fallback to random ID if node-machine-id fails
return crypto.randomUUID
? crypto.randomUUID()
: "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0;
const v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
try {
const cryptoFallback = await import("crypto");
return cryptoFallback.randomUUID();
} catch {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0;
const v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
}
}
@@ -44,13 +47,16 @@ export async function getRawMachineId() {
} catch (error) {
console.log("Error getting raw machine ID:", error);
// Fallback to random ID if node-machine-id fails
return crypto.randomUUID
? crypto.randomUUID()
: "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0;
const v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
try {
const cryptoFallback = await import("crypto");
return cryptoFallback.randomUUID();
} catch {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0;
const v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
}
}

View File

@@ -80,6 +80,9 @@ export const createComboSchema = z.object({
strategy: comboStrategySchema.optional().default("priority"),
config: comboConfigSchema,
allowedProviders: z.array(z.string().max(200)).optional(),
system_message: z.string().max(50000).optional(),
tool_filter_regex: z.string().max(1000).optional(),
context_cache_protection: z.boolean().optional(),
});
// ──── Auto-Combo Schemas ────
@@ -813,6 +816,9 @@ export const updateComboSchema = z
config: comboRuntimeConfigSchema.optional(),
isActive: z.boolean().optional(),
allowedProviders: z.array(z.string().max(200)).optional(),
system_message: z.string().max(50000).optional(),
tool_filter_regex: z.string().max(1000).optional(),
context_cache_protection: z.boolean().optional(),
})
.superRefine((value, ctx) => {
if (
@@ -821,7 +827,10 @@ export const updateComboSchema = z
value.strategy === undefined &&
value.config === undefined &&
value.isActive === undefined &&
value.allowedProviders === undefined
value.allowedProviders === undefined &&
value.system_message === undefined &&
value.tool_filter_regex === undefined &&
value.context_cache_protection === undefined
) {
ctx.addIssue({
code: z.ZodIssueCode.custom,