fix(server): provider updates on macOS use the system proxy #36301
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -0,0 +50,21 @@50+ const port = fields.get(`${scheme}Port`) ?? "";51+ // The password of an authenticated proxy is in the keychain, out of reach.52+ if (fields.get(`${scheme}Enable`) !== "1" || fields.has(`${scheme}User`) || !/^\d+$/.test(port)) {53+ return null;54+ }55+ if (host.includes(":")) {56+ return IPV6_ADDRESS.test(host) ? `http://[${host}]:${port}` : null;57+ }58+ return HOST_NAME.test(host) ? `http://${host}:${port}` : null;59+}60+61+/** NO_PROXY entries for one macOS exception, or null when no entry can express it. */62+function noProxyEntries(exception: string): ReadonlyArray<string> | null {63+ if (IPV4_EXCEPTION.test(exception)) {64+ return [];65+ }66+ if (exception.includes(":")) {67+ return IPV6_ADDRESS.test(exception) ? [exception, `[${exception}]`] : null;68+ }69+ const name = exception.startsWith("*.") ? exception.slice(1) : exception;70+ return HOST_NAME.test(name) ? [name] : null;@@ -0,0 +116,21 @@116+ spawner: ChildProcessSpawner.ChildProcessSpawner["Service"],117+ commandEnv: NodeJS.ProcessEnv = {},118+) {119+ if ((yield* HostProcess.Platform) !== "darwin") {120+ return {};121+ }122+ const env = { ...(yield* HostProcess.Environment), ...commandEnv };123+ const noProxy = [env.no_proxy, env.NO_PROXY]124+ .flatMap((value) => (value ?? "").split(","))125+ .flatMap((entry) => entry.trim() || []);126+ if (127+ PROXY_ENV_KEYS.some((key) => env[key] || env[key.toUpperCase()]) ||128+ // npm reads its own proxy settings from the environment too.129+ Object.keys(env).some((key) => /^npm_config_(https?[-_])?proxy$/i.test(key) && env[key]) ||130+ noProxy.includes("*")131+ ) {132+ return {};133+ }134+ const output = yield* spawner135+ .string(136+ ChildProcess.make("/usr/sbin/scutil", ["--proxy"], { stdin: "ignore", stderr: "ignore" }),
- @@ -0,0 +77,21 @@77+ if (host.includes(":")) {78+ return IPV6_ADDRESS.test(host) ? [host, `[${host}]`] : null;79+ }80+ const name = host.startsWith("*.") ? host.slice(1) : host;81+ return HOST_NAME.test(name) ? [name] : null;82+}83+84+/**85+ * Maps `scutil -d --proxy` output to proxy env vars, or to nothing when the env vars would proxy a86+ * request macOS sends directly. SOCKS is not used.87+ */88+export function macosSystemProxyEnv(89+ scutilOutput: string,90+ existingNoProxy: ReadonlyArray<string> = [],91+): Record<string, string> {92+ const { fields, exceptions, hasDomainProxies } = readScutilProxy(scutilOutput);93+ const http = proxyUrl(fields, "HTTP");94+ const https = proxyUrl(fields, "HTTPS");95+ const exceptionEntries = exceptions.map(noProxyEntries);96+ if (97+ (!http && !https) ||@@ -0,0 +1,5 @@1+import * as HostProcess from "@t3tools/shared/HostProcess";2+import * as Effect from "effect/Effect";3+import { ChildProcess, ChildProcessSpawner } from "effect/process";4+5+const PROXY_ENV_KEYS = ["http_proxy", "https_proxy", "all_proxy"];
- @@ -0,0 +101,21 @@101+ fields.get("ProxyAutoDiscoveryEnable") === "1" ||102+ // A VPN's per-domain proxies; one set of variables cannot route by domain.103+ hasDomainProxies ||104+ // No NO_PROXY entry matches every dotless host.105+ fields.get("ExcludeSimpleHostnames") === "1" ||106+ exceptionEntries.includes(null)107+ ) {108+ return {};109+ }110+ const noProxy = [111+ ...new Set([112+ ...existingNoProxy,113+ ...LOOPBACK_DIRECT,114+ ...exceptionEntries.flatMap((entries) => entries ?? []),115+ ...IPV4_DIRECT,116+ ]),117+ ].join(",");118+ // Each scheme keeps its own proxy, except in npm, which sends http requests through https_proxy.119+ return {120+ ...(http ? { HTTP_PROXY: http, http_proxy: http } : {}),121+ ...(https ? { HTTPS_PROXY: https, https_proxy: https } : {}),
Sign in to join this conversation.
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — macOS provider updates now automatically use supported system proxy settings, changing their default network routing. Human review is required to confirm that default; two supplied findings also identify npm routing conflicts covered by the separate blocking gate.
Needs human approval because:
- 2 blocking correctness issues found at or above your repo's Minimum Blocking Severity
Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).