mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #7729] [MERGED] fix(server): send provider requests through HTTP(S)_PROXY when NODE_USE_ENV_PROXY is on #7901
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#7901
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7729
Author: @SpicyMarinara
Created: 10/16/2026
Status: ✅ Merged
Merged: 10/16/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/7652-llm-proxy-env📝 Commits (2)
d8f2165fix(server): send provider requests through HTTP(S)_PROXY when NODE_USE_ENV_PROXY is onefd77dcdocs(server): note that a proxy resolves the provider name itself📊 Changes
2 files changed (+125 additions, -6 deletions)
View changed files
📝
packages/server/src/utils/security.ts(+28 -6)➕
scripts/regressions/llm-env-proxy.regression.ts(+97 -0)📄 Description
Linked issue
Closes #7652
Why this change
HTTP_PROXY/HTTPS_PROXYwithNODE_USE_ENV_PROXY=1, for example v2rayN without TUN mode) could fetch the model list, but every test message and reply failed withfetch failedafter about 10 seconds.NODE_USE_ENV_PROXY=1, Node puts a proxy-aware agent behind its ownfetch.safeFetchpassed its own undiciAgentas thedispatcher, which replaces that global agent, so those requests went direct and hit the 10-second connect timeout. The model list worked only because, withPROVIDER_LOCAL_URLS_ENABLED=trueand no timeouts to set, it kept Node's default agent. Chat calls always set timeouts. With local URLs off, the model list skipped the proxy too, because of the pinned DNS agent.What changed
packages/server/src/utils/security.ts: both places wheresafeFetchbuilds its own agent now call onecreateDispatcherhelper. When Node's env proxy switch is on (NODE_USE_ENV_PROXY=1or--use-env-proxy) and a proxy variable is set, it builds an undiciEnvHttpProxyAgentwith the same timeout options. Otherwise it builds the sameAgentas before.NO_PROXYhosts use that agent's plain inner agent, which keeps the pinned address lookup. Loopback names and addresses (localhost,127.0.0.1,::1) always stay direct.safeFetchcaller that sets timeouts or uses the pinned lookup: chat and test messages (llmFetch), image generation, embeddings, package downloads and model lists with local URLs off.scripts/regressions/llm-env-proxy.regression.ts: a local fake CONNECT proxy and target, each with one fixed answer for every route. With local URLs both off and on, it checks that anllmFetchprovider call goes through the proxy, that aNO_PROXYhost and127.0.0.1/localhoststay direct, and that nothing is proxied withoutNODE_USE_ENV_PROXY. Before the fix it fails with'direct' !== 'proxy', in both local-URL modes.Decisions to review
NODE_USE_ENV_PROXY=1(or--use-env-proxy) is set, so people withHTTP_PROXYset for other tools see no change.NO_PROXYdoesn't list it, as it did before. This keeps local backends such as KoboldCpp or llama.cpp working for anyone who sets a proxy but forgetsNO_PROXY. Other LAN or private hosts followNO_PROXY, as Node's ownfetchdoes.fetch). With local URLs disabled, the destination must still resolve locally: proxy-only DNS is an existing limitation retained by this fix.http://proxy receives its own proxy credentials over HTTP, exactly as Node's built-in fetch does; this change does not add provider credentials to the proxy URL. Rejecting or stripping proxy authentication would break authenticated HTTP proxies, including loopback proxies. HTTPS proxy transport remains available when encryption is required for that connection.Validation
pnpm checkpasses locallyCONTRIBUTING.mdRun by the agent:
npx tsc --noEmitfor shared, server, client and root: clean.prettier --checkon both changed files: clean.llm-env-proxy(new),localhost-loopback-fetch,llm-first-chunk-timeout,image-generation-timeout,image-result-url-security,swarmui-video-origin,provider-compat,opencode-session,extension-security,multiplayer-control-securityandopen-issuesall pass.llmFetchtohttps://example.com/through a local CONNECT proxy returned 200 with the real page in both local-URL modes. The proxy sawexample.com:443, so TLS works through the tunnel.Local CodeRabbit review (CLI, on
d8f2165ac): three findings, none changed the code.PROVIDER_LOCAL_URLS_ENABLED=true, which turns off the address check completely. The proxy also has to resolve names itself where local DNS is filtered, which is a common reason to use one. The local address check still runs first, and this only applies after someone opts in withNODE_USE_ENV_PROXY=1, the same as Node's ownfetch.efd77dc75adds a code comment about it. Listed under decisions above.scripts/run-regressions.mjsruns each file in its own child process (spawn).--use-env-proxyforms. Not taken: reading the switch on each request lets a.envreload apply without a restart (runtime-config.tswritesprocess.env). On Node 24.16,NODE_USE_ENV_PROXY=truedoes not turn on Node's proxy; only1does. I checked this, and the check matches it.Hosted CodeRabbit completed on
efd77dc75: two findings declined with source-based reasons in the review threads. Authenticated HTTP proxy transport is intentionally compatible with Node's explicit environment configuration. Proxy-only DNS remains outside this narrow dispatcher fix because the existing fail-closed address guard is retained; ordinary CONNECT does not expose the remote destination IP for equivalent validation.Manual verification notes
NODE_USE_ENV_PROXY=1,HTTPS_PROXY=http://127.0.0.1:<port>and a local HTTP proxy (for example v2rayN with TUN off), Test Message and a normal chat reply succeed for an OpenAI and a Custom OpenAI-compatible connection.PROVIDER_LOCAL_URLS_ENABLEDbothtrueandfalse.localhost/127.0.0.1(KoboldCpp, llama.cpp, Ollama) still answers directly with the proxy variables set.NO_PROXYis reached directly.NODE_USE_ENV_PROXY(proxy variables still set), generation behaves exactly as before.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)No docs are changed. The docs don't mention proxy variables today; a short
docs/CONFIGURATION.mdnote could be a follow-up.UI evidence (if applicable)
Not applicable (server only).
🤖 Generated with Claude Code
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.