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
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
fix(api,dashboard): validate /v1/images/edits JSON body + drop duplicate proxy handler
diegosouzapw396a79f02a07
diff --git a/src/app/(dashboard)/dashboard/providers/[id]/page.tsx b/src/app/(dashboard)/dashboard/providers/[id]/page.tsxindex b23b051841..cee9027a2c 100644--- a/src/app/(dashboard)/dashboard/providers/[id]/page.tsx+++ b/src/app/(dashboard)/dashboard/providers/[id]/page.tsx@@ -2587,127 +2587,6 @@ export default function ProviderDetailPage() {}};- const handleToggleProxyEnabled = async (connectionId, proxyEnabled) => {- try {- const res = await fetch(`/api/providers/${connectionId}`, {- method: "PUT",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({ proxyEnabled }),- });- if (res.ok) {- setConnections((prev) =>- prev.map((c) => (c.id === connectionId ? { ...c, proxyEnabled } : c))- );- }- } catch (error) {- console.error("Error toggling proxy enabled:", error);- }- };-- const handleTogglePerKeyProxyEnabled = async (connectionId, perKeyProxyEnabled) => {- try {- const res = await fetch(`/api/providers/${connectionId}`, {- method: "PUT",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({ perKeyProxyEnabled }),- });- if (res.ok) {- setConnections((prev) =>- prev.map((c) => (c.id === connectionId ? { ...c, perKeyProxyEnabled } : c))- );- }- } catch (error) {- console.error("Error toggling per-key proxy enabled:", error);- }- };-- const handleDistributeProxies = async (tagFilter?: string) => {- const targetConnections = tagFilter- ? connections.filter(- (c: any) =>- (c.providerSpecificData?.tag as string | undefined)?.trim() === tagFilter- )- : connections;- if (targetConnections.length === 0) return;- setDistributingProxies(true);- try {- const proxiesRes = await fetch("/api/settings/proxies");- if (!proxiesRes.ok) throw new Error("Failed to fetch proxies");- const proxiesData = await proxiesRes.json();- const savedProxies = (proxiesData?.items || []).filter(- (p: any) => p.status === "active"- );- if (savedProxies.length === 0) {- notify.error("No saved proxies found. Add proxies in Settings → Proxy first.");- return;- }-- let assigned = 0;- const sorted = [...targetConnections].sort(- (a: any, b: any) => (a.priority || 0) - (b.priority || 0)- );-- for (let i = 0; i < sorted.length; i++) {- const conn = sorted[i] as any;- const proxy = savedProxies[i % savedProxies.length];-- try {- await fetch("/api/settings/proxies/assignments", {- method: "PUT",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({- scope: "account",- scopeId: conn.id,- proxyId: null,- }),- });- } catch {- /* clear old assignment */- }-- const patchRes = await fetch(`/api/providers/${conn.id}`, {- method: "PUT",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({ proxyEnabled: true, perKeyProxyEnabled: true }),- });-- if (!patchRes.ok) {- console.error(`Failed to update connection ${conn.id}`);- continue;- }-- // Assign new proxy- const assignRes = await fetch("/api/settings/proxies/assignments", {- method: "PUT",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({- scope: "account",- scopeId: conn.id,- proxyId: proxy.id,- }),- });-- if (!assignRes.ok) {- console.error(`Failed to assign proxy to ${conn.id}`);- continue;- }-- assigned++;- }-- await fetchConnections();- const tagLabel = tagFilter ? `"${tagFilter}" ` : "";- notify.success(- `Distributed ${assigned} proxy assignment(s) across ${tagLabel}${sorted.length} connection(s).`- );- } catch (err) {- console.error("Error distributing proxies:", err);- notify.error("Failed to distribute proxies.");- } finally {- setDistributingProxies(false);- }- };-const handleToggleRateLimit = async (connectionId, enabled) => {try {const res = await fetch("/api/rate-limits", {diff --git a/src/app/api/v1/images/edits/route.ts b/src/app/api/v1/images/edits/route.tsindex 9c6b18a0bc..ac0808a5cb 100644--- a/src/app/api/v1/images/edits/route.ts+++ b/src/app/api/v1/images/edits/route.ts@@ -13,6 +13,22 @@ import {resolveImageRouteModel,extractImageEditInputFromJson,} from "@/lib/images/imageRouteModel";+import { z } from "zod";++// JSON edit body (Open WebUI / OpenAI-style). All fields optional — the prompt+// and resolvable image are enforced after extraction in POST — but the top-level+// shape must be an object with correctly-typed fields, so a malformed body+// (array, string, wrong types) is rejected with 400 instead of silently parsed.+const ImageEditJsonSchema = z+ .object({+ prompt: z.string().optional(),+ model: z.string().optional(),+ size: z.string().optional(),+ response_format: z.string().optional(),+ image: z.unknown().optional(),+ images: z.array(z.unknown()).optional(),+ })+ .passthrough();/*** /v1/images/edits — OpenAI-compatible image-edit endpoint.@@ -99,7 +115,12 @@ async function readEditInput(request: Request): Promise<EditInput | null> {}if (contentType.includes("application/json")) {try {- return extractImageEditInputFromJson(await request.json());+ const parsed = ImageEditJsonSchema.safeParse(await request.json());+ if (!parsed.success) {+ log.warn("IMAGE", `Invalid JSON edit body shape: ${parsed.error.message}`);+ return null;+ }+ return extractImageEditInputFromJson(parsed.data);} catch (err) {log.warn("IMAGE", `Invalid JSON edit body: ${err instanceof Error ? err.message : err}`);return null;