fix(proxy): make auto-selection fallback opt-in (#3332) (#3344)

selectWorkingProxyFallback (Step 11 of resolveProxyForConnection) listed ALL
registry proxies, ignoring assignments and per-connection proxy_enabled, and
returned the first working one with level:'autoSelect'. So a single proxy added
to the registry silently became a global fallback for every connection's traffic.

Gate it behind a new PROXY_AUTO_SELECT_ENABLED feature flag (default off): the
fallback now no-ops unless the operator opts in. No registry proxy becomes a
silent global default anymore.

Co-authored-by: hertznsk <hertznsk@users.noreply.github.com>
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-06-06 22:58:18 -03:00
committed by GitHub
parent 23d7bd1589
commit f89b5c5e46
4 changed files with 75 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ _Development cycle in progress — entries are added as work merges into `releas
### 🔧 Bug Fixes
- **fix(proxy):** proxy auto-selection is now **opt-in** (new `PROXY_AUTO_SELECT_ENABLED` flag, default off). Previously a single proxy in the registry silently became a global fallback for **all** provider connections (the Step-11 fallback listed every registry proxy, ignoring assignments and per-connection `proxy_enabled`). It now no-ops unless the operator enables the flag. (#3332 — thanks @hertznsk)
- **fix(cli):** write the OpenCode config to `~/.config/opencode/opencode.json` on **all** platforms — on Windows OmniRoute wrote to `%APPDATA%\opencode\` but OpenCode reads from `%USERPROFILE%\.config\opencode\` (XDG), so dashboard-saved config silently had no effect. (#3330 — thanks @abdulkadirozyurt)
- **fix(catalog):** remove `minimaxai/minimax-m3` from the **NVIDIA NIM** tier — NVIDIA does not host it yet, so every request 404'd (`404 page not found`), while sibling `minimax-m2.7` on the same provider works. MiniMax M3 stays available on the tiers that actually serve it. (#3329 — thanks @mikmaneggahommie)
- **fix(electron):** ship `loginManager.js` in the packaged app — #3292 added it (and a `require("./loginManager")` in `main.js`) without adding it to electron-builder's `build.files`, so the packaged app crashed at startup with "Cannot find module" on the Linux/macOS smoke tests. Plus a regression test asserting every local `require("./x")` in the Electron entry points is shipped. ([#3334](https://github.com/diegosouzapw/OmniRoute/pull/3334) — thanks @diegosouzapw)

View File

@@ -10,6 +10,7 @@
import { fetch as undiciFetch } from "undici";
import { createProxyDispatcher, normalizeProxyUrl } from "./proxyDispatcher.ts";
import { resolveProxyForScopeFromRegistry, listProxies, listOneproxyProxies } from "@/lib/localDb";
import { isFeatureFlagEnabled } from "@/shared/utils/featureFlags";
// ---------------------------------------------------------------------------
// Types
@@ -347,6 +348,12 @@ export async function selectWorkingProxyFallback(
levelId: string | null;
source: string;
} | null> {
// #3332: auto-selection is opt-in. Without this gate, any single proxy in the
// registry silently becomes a global fallback for ALL connections (ignoring
// assignments / per-connection proxy_enabled). Default OFF — only run when the
// operator explicitly enables PROXY_AUTO_SELECT_ENABLED.
if (!isFeatureFlagEnabled("PROXY_AUTO_SELECT_ENABLED")) return null;
const candidates = await getProxyCandidates();
if (candidates.length === 0) return null;

View File

@@ -117,6 +117,18 @@ export const FEATURE_FLAG_DEFINITIONS: FeatureFlagDefinition[] = [
requiresRestart: false,
warningLevel: "info",
},
{
key: "PROXY_AUTO_SELECT_ENABLED",
label: "Proxy Auto-Selection Fallback",
description:
"When no proxy is assigned to a connection, auto-select the first working proxy from the registry. Off by default — otherwise any single registry proxy becomes a global fallback for all traffic (#3332).",
descriptionI18nKey: "settings.featureFlags.proxyAutoSelectEnabled",
category: "network",
defaultValue: "false",
type: "boolean",
requiresRestart: false,
warningLevel: "caution",
},
{
key: "MITM_DISABLE_TLS_VERIFY",
label: "Disable TLS Verify (MITM)",

View File

@@ -0,0 +1,55 @@
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-proxy-3332-"));
process.env.DATA_DIR = TEST_DATA_DIR;
const core = await import("../../src/lib/db/core.ts");
const { FEATURE_FLAG_DEFINITIONS } = await import(
"../../src/shared/constants/featureFlagDefinitions.ts"
);
const { isFeatureFlagEnabled } = await import("../../src/shared/utils/featureFlags.ts");
const { selectWorkingProxyFallback } = await import("../../open-sse/utils/proxyFallback.ts");
// #3332: a single proxy in the registry was silently applied to ALL connections
// via the auto-selection fallback. The fix makes auto-selection opt-in behind
// PROXY_AUTO_SELECT_ENABLED, default OFF — so no registry proxy becomes a global
// default unless the operator explicitly turns it on.
test("PROXY_AUTO_SELECT_ENABLED exists and defaults to off (opt-in) (#3332)", () => {
const def = FEATURE_FLAG_DEFINITIONS.find((d) => d.key === "PROXY_AUTO_SELECT_ENABLED");
assert.ok(def, "PROXY_AUTO_SELECT_ENABLED flag must be defined");
assert.equal(def.defaultValue, "false", "auto-selection must be opt-in (default off)");
delete process.env.PROXY_AUTO_SELECT_ENABLED;
assert.equal(isFeatureFlagEnabled("PROXY_AUTO_SELECT_ENABLED"), false);
});
test("selectWorkingProxyFallback short-circuits to null when the flag is off, even with a candidate", async () => {
delete process.env.PROXY_AUTO_SELECT_ENABLED;
const prevAllProxy = process.env.ALL_PROXY;
// A candidate exists (env proxy) — yet auto-selection must NOT run while off.
process.env.ALL_PROXY = "http://127.0.0.1:1";
try {
const result = await selectWorkingProxyFallback("conn-1");
assert.equal(result, null, "no auto-selected proxy while the flag is off");
} finally {
if (prevAllProxy === undefined) delete process.env.ALL_PROXY;
else process.env.ALL_PROXY = prevAllProxy;
}
});
test.after(() => {
try {
core.resetDbInstance?.();
} catch {
/* ignore */
}
try {
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
} catch {
/* ignore */
}
});