Repository navigation
fix(api): honor proxy config for direct API calls - #1543
Merged
Benjamin Barslev Nielsen (barslev) merged 1 commit intoSep 17, 2026
Merged
Conversation
setupSdk builds an hpagent proxy agent from SOCKET_CLI_API_PROXY, falling back to HTTPS_PROXY/HTTP_PROXY, but apiFetch built a plain https.Agent and connected directly. Every call that bypasses the SDK ignored the proxy: scan report data, scan view, scan diff, package score, threat-feed, and tier1 reachability finalize. Where a proxy is merely preferred this is invisible, because the direct connection succeeds anyway. Where the proxy is the only egress route it fails outright with `getaddrinfo EAI_AGAIN api.socket.dev`, while SDK requests issued concurrently still succeed. Build the same proxy agent in getHttpsAgent so both stacks agree. The destination CA is passed as before; the CA for the hop to an https:// proxy goes in proxyRequestOptions, which is the option hpagent actually reads.
Benjamin Barslev Nielsen (barslev)
requested a review
from Oskar Haarklou Veileborg (BarrensZeppelin)
September 17, 2026 11:02
Oskar Haarklou Veileborg (BarrensZeppelin)
approved these changes
Sep 17, 2026
Benjamin Barslev Nielsen (barslev)
deleted the
barslev/fix-apifetch-proxy-support
branch
September 17, 2026 11:14
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LLM Description written by Claude Code:Claude Opus 5
setupSdkbuilds an hpagent proxy agent fromSOCKET_CLI_API_PROXY, falling back toHTTPS_PROXY/https_proxy/HTTP_PROXY/http_proxy, and hands it to socket-sdk-js.apiFetchbuilt a plainhttps.Agentand connected straight out, so every call that bypasses the typed SDK ignored the proxy entirely:socket scan create --report,socket scan report)socket scan viewsocket scan diffsocket package scoresocket threat-feedThat split isn't accidental — those endpoints skip the SDK because they aren't in the OpenAPI spec, as the comment in
finalize-tier1-scan.mtssays. The second stack was added for a good reason and silently never inherited the proxy handling.Why this went unnoticed since #526
Setting a proxy env var doesn't mean direct egress is blocked. In most setups the proxy is a policy preference and direct outbound still works, so
apiFetchignoring it is invisible — the request just goes direct and succeeds. It only fails where the proxy is the sole route out. There,socket scan create --reportdies withgetaddrinfo EAI_AGAIN api.socket.dev— a DNS failure, meaning the request never left the machine — while the org-security-policy request issued concurrently in the samePromise.allthrough the SDK succeeds.This is a different failure class from #1124 and the equivalent coana fix from April 2026, which both addressed CA trust behind intercepting proxies (
unable to get local issuer certificate,packet length too long). In those environments DNS and direct connections work and only the certificate is wrong, so routing was never addressed.The change
getHttpsAgent()now builds the same proxy agentsetupSdkdoes.apiFetchneeds no change — it already routes everything through_httpsRequestFetchwith whatever explicit agent that function returns, so this is a single seam covering all six commands.getDefaultProxyUrlis imported fromsdk.mtsrather than reimplemented, so the two stacks can't drift on which env vars they read.Also adds tests pinning proxy routing, since the absence of any such test is why this stayed invisible. They were checked against the unpatched tree — both fail without the change.
Worth a look
proxyRequestOptionsfor the CA on the proxy hop, whilesdk.mtspassesproxyConnectOptions. hpagent 1.2.0 destructures onlyproxyRequestOptions, so thesdk.mtsvalue is silently dropped, andsdk.test.mtspins the wrong key against a mocked constructor so it passes regardless. Impact there is narrow — top-levelcastill covers the destination handshake, so only the CA for connecting to anhttps://proxy is lost. Left alone to keep this to one behaviour change; happy to fold it in.NO_PROXYis still unhonored (hpagent doesn't implement it, andsetupSdkhas the same gap), andapi.mtsstill has no retry logic. Both deliberate non-goals.Note
Medium Risk
Changes outbound networking for all non-SDK API traffic; behavior is limited to environments with proxy env vars set and aligns with existing SDK proxy handling.
Overview
Direct
apiFetchcalls now honor the same proxy settings as the Socket SDK, fixing failures in proxy-only networks where commands like scan report/view/diff bypassed the SDK.getHttpsAgent()inapi.mtsreadsgetDefaultProxyUrl()fromsdk.mtsand builds anhpagentHttpsProxyAgentwhen a proxy is set; otherwise it keeps the existing plainHttpsAgentbehavior. When extra CA certs are configured, both the destination TLS handshake and the proxy hop (proxyRequestOptions.ca) get those certs.Unit tests mock
hpagentand assert proxy routing, CA wiring on proxy + destination, and the no-proxy fallback.Reviewed by Cursor Bugbot for commit c277e7b. Configure here.