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

Merge remote-tracking branch 'origin/release/v3.7.0' into release/v3.7.0

diegosouzapw1dae161823b7
diff --cc src/lib/db/encryption.ts
index 07ab9db803,b491a09a47..80a27aba7b
--- a/src/lib/db/encryption.ts
+++ b/src/lib/db/encryption.ts
@@@ -154,27 -131,23 +156,38 @@@ export function decrypt(ciphertext: str
decipher.setAuthTag(authTag);
let decrypted = decipher.update(encryptedHex, "hex", "utf8");
- decrypted += decipher.final("utf8");
+ try {
+ decrypted += decipher.final("utf8");
+ } catch (finalErr: unknown) {
+ const finalMessage = finalErr instanceof Error ? finalErr.message : String(finalErr);
+ console.error(
+ `[Encryption] Decryption final() failed: ${finalMessage}. ` +
+ `Ciphertext prefix: ${ciphertext.slice(0, 30)}... ` +
+ `Auth tag validation likely failed.`
+ );
+ return ciphertext;
+ }
return decrypted;
} catch (err: unknown) {
+ const legacyKey = getLegacyKey();
+ if (legacyKey) {
+ try {
+ const iv = Buffer.from(ivHex, "hex");
+ const authTag = Buffer.from(authTagHex, "hex");
+ const legacyDecipher = createDecipheriv(ALGORITHM, legacyKey, iv);
+ legacyDecipher.setAuthTag(authTag);
+
+ let legacyDecrypted = legacyDecipher.update(encryptedHex, "hex", "utf8");
+ legacyDecrypted += legacyDecipher.final("utf8");
+ return legacyDecrypted;
+ } catch (legacyErr) {
+ // Fallback failed as well
+ }
+ }
const message = err instanceof Error ? err.message : String(err);
console.error("[Encryption] Decryption failed:", message);
- return ciphertext;
+ // Return null instead of encrypted ciphertext to prevent sending encrypted tokens to providers
+ return null;
}
}