Skip to content

Commit 78dda62

Browse files
rekram1-noder266-techPJ-Zetier
authored
fix(cli): keep loopback requests off environment proxies (#60441)
Co-authored-by: r266-tech <r266-tech@users.noreply.github.com> Co-authored-by: pj.reid <pj.reid@zetier.com>
1 parent ef712d3 commit 78dda62

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

‎packages/cli/src/index.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ import { Heap } from "./heap"
1919
import { CpuProfile } from "./cpu-profile"
2020
import { ShutdownDeadline } from "./shutdown-deadline"
2121

22+
// Keep requests to the local service off any proxy. Bun reads lowercase `no_proxy` alone whenever it is set, so both
23+
// spellings get the same merged list.
24+
const noProxy = [
25+
...new Set(
26+
[process.env.NO_PROXY, process.env.no_proxy, "127.0.0.1,localhost,::1"].flatMap((value) =>
27+
(value ?? "").split(",").flatMap((entry) => entry.trim() || []),
28+
),
29+
),
30+
].join(",")
31+
32+
process.env.NO_PROXY = noProxy
33+
process.env.no_proxy = noProxy
34+
2235
ensurePluginRuntime()
2336

2437
if (process.env.OPENCODE_SSH_ASKPASS_PORT) {

‎packages/desktop/src/main/lifecycle/environment.ts‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,16 @@ const loadSystemCertificates = Effect.try({
7070
catch: (error) => error,
7171
}).pipe(Effect.catch((error) => Effect.logWarning("failed to load system certificates", { error })))
7272

73+
// Bun reads lowercase `no_proxy` alone whenever it is set, so both spellings get the same merged list.
7374
function ensureLoopbackNoProxy() {
74-
const loopback = ["127.0.0.1", "localhost", "::1"]
75+
const noProxy = [
76+
...new Set(
77+
[process.env.NO_PROXY, process.env.no_proxy, "127.0.0.1,localhost,::1"].flatMap((value) =>
78+
(value ?? "").split(",").flatMap((entry) => entry.trim() || []),
79+
),
80+
),
81+
].join(",")
7582

76-
;["NO_PROXY", "no_proxy"].forEach((key) => {
77-
const items = (process.env[key] ?? "")
78-
.split(",")
79-
.map((value) => value.trim())
80-
.filter(Boolean)
81-
82-
loopback.forEach((host) => {
83-
if (!items.some((value) => value.toLowerCase() === host)) items.push(host)
84-
})
85-
process.env[key] = items.join(",")
86-
})
83+
process.env.NO_PROXY = noProxy
84+
process.env.no_proxy = noProxy
8785
}

0 commit comments

Comments
 (0)