Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix(auth): use timing-safe compare for INITIAL_PASSWORD check

jack55a9e3193278
diff --git a/src/app/api/settings/route.ts b/src/app/api/settings/route.ts
index 23eb0355d9..28dcdc66f0 100644
--- a/src/app/api/settings/route.ts
+++ b/src/app/api/settings/route.ts
@@ -2,6 +2,7 @@ import { NextResponse } from "next/server";
import { getSettings, updateSettings } from "@/lib/localDb";
import { clearHealthCheckLogCache } from "@/lib/tokenHealthCheck";
import bcrypt from "bcryptjs";
+import { timingSafeEqual } from "node:crypto";
import { getRuntimePorts } from "@/lib/runtime/ports";
import { updateSettingsSchema } from "@/shared/validation/settingsSchemas";
import { isValidationFailure, validateBody } from "@/shared/validation/helpers";
@@ -70,7 +71,14 @@ export async function PATCH(request) {
if (!currentPassword) {
return NextResponse.json({ error: "Current password required" }, { status: 400 });
}
- if (currentPassword !== initialPassword) {
+
+ const providedBuffer = Buffer.from(currentPassword, "utf8");
+ const expectedBuffer = Buffer.from(initialPassword, "utf8");
+ const isValidInitialPassword =
+ providedBuffer.length === expectedBuffer.length &&
+ timingSafeEqual(providedBuffer, expectedBuffer);
+
+ if (!isValidInitialPassword) {
return NextResponse.json({ error: "Invalid current password" }, { status: 401 });
}
} else {