Repository navigation
fix: honor OS-level PAC configuration in system proxy mode - #7766
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds end-to-end PAC (Proxy Auto-Config) support: proxy detectors return ChangesSystem PAC / Proxy resolution (single cohesive cohort)
Sequence Diagram(s)sequenceDiagram
actor Client
participant OS as OS Detector
participant Resolver as PAC Resolver
participant Agent as HTTP/HTTPS Agent
participant Server as Target Server
Client->>OS: request ProxyConfiguration for URL
OS-->>Client: { http_proxy, https_proxy, no_proxy, pac_url }
alt pac_url present
Client->>Resolver: fetch & evaluate PAC for request URL
Resolver->>Resolver: execute PAC → directive(s)
alt directive is PROXY / SOCKS
Resolver-->>Client: return proxy agent
else directive is DIRECT or no match
Resolver-->>Client: return direct (no agent)
end
else no pac_url
Client->>Client: apply http_proxy/https_proxy + no_proxy rules
end
Client->>Agent: send request via chosen agent
Agent->>Server: (proxied or direct) request
Server-->>Agent: response
Agent-->>Client: response
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (4)
packages/bruno-electron/src/utils/proxy-util.js (1)
107-134: Inconsistent agent assignment compared tohttp-https-agents.ts.This helper sets both
httpAgentandhttpsAgentregardless of request protocol, while the equivalentresolveAgentsFromPacinhttp-https-agents.ts(lines 424-437) selectively sets only the needed agent based onisHttpsRequest. This could cause unnecessary agent creation.Consider aligning the behavior by passing
isHttpsRequestand conditionally setting only the required agent.♻️ Suggested approach
-async function resolveAgentsFromPac({ pacSource, requestUrl, requestConfig, tlsOptions, httpsAgentRequestFields, timeline, disableCache, hostname }) { +async function resolveAgentsFromPac({ pacSource, requestUrl, requestConfig, tlsOptions, httpsAgentRequestFields, timeline, disableCache, hostname, isHttpsRequest }) { const resolver = await getPacResolver({ pacSource, httpsAgentRequestFields }); const directives = await resolver.resolve(requestUrl); if (!directives || !directives.length) { return null; } const first = directives[0]; if (/^(PROXY|HTTPS?)\s+/i.test(first)) { const parts = first.split(/\s+/); const keyword = parts[0].toUpperCase(); const hostPort = parts[1]; const scheme = keyword === 'HTTPS' ? 'https' : 'http'; const proxyUri = `${scheme}://${hostPort}`; - requestConfig.httpAgent = getOrCreateHttpAgent({ AgentClass: HttpProxyAgent, options: { keepAlive: true }, proxyUri, timeline, disableCache, hostname }); - requestConfig.httpsAgent = getOrCreateHttpsAgent({ AgentClass: PatchedHttpsProxyAgent, options: tlsOptions, proxyUri, timeline, disableCache, hostname }); + if (isHttpsRequest) { + requestConfig.httpsAgent = getOrCreateHttpsAgent({ AgentClass: PatchedHttpsProxyAgent, options: tlsOptions, proxyUri, timeline, disableCache, hostname }); + } else { + requestConfig.httpAgent = getOrCreateHttpAgent({ AgentClass: HttpProxyAgent, options: { keepAlive: true }, proxyUri, timeline, disableCache, hostname }); + } } else if (/^SOCKS/i.test(first)) { // ... similar change for SOCKS } return directives; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-electron/src/utils/proxy-util.js` around lines 107 - 134, The resolveAgentsFromPac function currently assigns both requestConfig.httpAgent and requestConfig.httpsAgent unconditionally, creating unnecessary agents; update resolveAgentsFromPac to accept an isHttpsRequest boolean (like in http-https-agents.ts) and only call getOrCreateHttpAgent when !isHttpsRequest and only call getOrCreateHttpsAgent/appropriate Agent when isHttpsRequest, preserving the existing proxyUri/scheme/proto logic and using the same AgentClass and options (HttpProxyAgent, PatchedHttpsProxyAgent, SocksProxyAgent) so you avoid instantiating the unused agent.packages/bruno-requests/src/network/system-proxy/utils/linux.ts (1)
90-95: Consider addingpac_url: nullto manual proxy returns for type consistency.The PAC code paths return
{ pac_url, ... }but the manual proxy returns here (and ingetKDEProxy,parseProxyFromContent) omitpac_url. This inconsistency may cause downstream code to handleundefinedvsnulldifferently.♻️ Suggested fix
return { http_proxy, https_proxy, no_proxy: normalizeNoProxy(rawNoProxy), + pac_url: null, source: 'linux-system' };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-requests/src/network/system-proxy/utils/linux.ts` around lines 90 - 95, The manual proxy return objects lack a pac_url field causing type inconsistency; update the manual-return branches in the linux-system code (the return currently including http_proxy, https_proxy, no_proxy, source: 'linux-system') as well as corresponding manual-return spots in getKDEProxy and parseProxyFromContent to include pac_url: null so all proxy result objects always have a pac_url property (PAC code paths should continue to return the actual pac_url).packages/bruno-requests/src/network/system-proxy/utils/windows.ts (1)
220-226: Consider addingpac_url: nullfor consistency with the PAC code path.Same observation as the Linux file:
parseProxyStringreturns aProxyConfigurationwithoutpac_url, creating a shape inconsistency with configurations that include it.♻️ Suggested fix
return { http_proxy, https_proxy, no_proxy: bypassList && bypassList !== '(none)' ? normalizeNoProxy(bypassList) : null, + pac_url: null, source: 'windows-system' };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-requests/src/network/system-proxy/utils/windows.ts` around lines 220 - 226, The returned ProxyConfiguration from the Windows system parser (the object returned in the function that uses http_proxy, https_proxy and normalizeNoProxy) is missing pac_url which causes shape inconsistency with the PAC code path; update the returned object in the Windows parser (the same place parseProxyString/normalizeNoProxy are used) to include pac_url: null so ProxyConfiguration always has pac_url present.tests/proxy/system-pac/system-pac-proxy.spec.ts (1)
25-35: Consider try/finally pattern for system state cleanup.If
startServers()succeeds but a test fails mid-execution,disableSystemPac()still runs viaafterAll. However, ifenableSystemPac()throws (e.g., permission denied), the system may be left in an inconsistent state. Consider wrappingenableSystemPaccalls with their own error handling.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/proxy/system-pac/system-pac-proxy.spec.ts` around lines 25 - 35, The before/after hooks should ensure enableSystemPac failures can't leave the OS proxy set; wrap calls to enableSystemPac (and any system-modifying setup) in a try/finally so disableSystemPac always runs on error: modify the setup where startServers() and enableSystemPac() are invoked (referencing startServers, enableSystemPac, disableSystemPac, stopServers) to catch exceptions from enableSystemPac and call disableSystemPac in a finally block, and ensure stopServers is awaited in the cleanup path as well so servers are stopped whether setup succeeds or fails.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/bruno-requests/src/network/system-proxy/utils/macos.spec.ts`:
- Around line 48-49: Add a positive PAC-enabled test in macos.spec.ts that
exercises the new PAC extraction path: create a test case that stubs/mocks the
macOS system proxy output to include a PAC URL and assert that the parsed result
(the object under test that currently exposes pac_url) returns that non-null URL
(not null) and retains source: 'macos-system'; locate the spec in
packages/bruno-requests/src/network/system-proxy/utils/macos.spec.ts and add the
test alongside the existing cases that currently assert pac_url: null so it
covers the PAC-enabled branch of the parsing function that produces pac_url.
In `@tests/proxy/system-pac/system-pac-proxy.spec.ts`:
- Around line 12-20: The test hardcodes NETWORK_SERVICE = 'Wi-Fi' and calls
macOS-only networksetup without platform guarding; update the test to first skip
on non-Darwin platforms (use a platform check and test.skip) and make
NETWORK_SERVICE dynamic by detecting an active service or accepting the service
name from environment/utility instead of hardcoding; locate the NETWORK_SERVICE
constant and the helper functions enableSystemPac and disableSystemPac and
change them to either query available services (e.g., via networksetup
-listallnetworkservices) or accept a resolved service name, and ensure the
entire test is wrapped with a Darwin-only guard so networksetup is never invoked
on other OSes.
---
Nitpick comments:
In `@packages/bruno-electron/src/utils/proxy-util.js`:
- Around line 107-134: The resolveAgentsFromPac function currently assigns both
requestConfig.httpAgent and requestConfig.httpsAgent unconditionally, creating
unnecessary agents; update resolveAgentsFromPac to accept an isHttpsRequest
boolean (like in http-https-agents.ts) and only call getOrCreateHttpAgent when
!isHttpsRequest and only call getOrCreateHttpsAgent/appropriate Agent when
isHttpsRequest, preserving the existing proxyUri/scheme/proto logic and using
the same AgentClass and options (HttpProxyAgent, PatchedHttpsProxyAgent,
SocksProxyAgent) so you avoid instantiating the unused agent.
In `@packages/bruno-requests/src/network/system-proxy/utils/linux.ts`:
- Around line 90-95: The manual proxy return objects lack a pac_url field
causing type inconsistency; update the manual-return branches in the
linux-system code (the return currently including http_proxy, https_proxy,
no_proxy, source: 'linux-system') as well as corresponding manual-return spots
in getKDEProxy and parseProxyFromContent to include pac_url: null so all proxy
result objects always have a pac_url property (PAC code paths should continue to
return the actual pac_url).
In `@packages/bruno-requests/src/network/system-proxy/utils/windows.ts`:
- Around line 220-226: The returned ProxyConfiguration from the Windows system
parser (the object returned in the function that uses http_proxy, https_proxy
and normalizeNoProxy) is missing pac_url which causes shape inconsistency with
the PAC code path; update the returned object in the Windows parser (the same
place parseProxyString/normalizeNoProxy are used) to include pac_url: null so
ProxyConfiguration always has pac_url present.
In `@tests/proxy/system-pac/system-pac-proxy.spec.ts`:
- Around line 25-35: The before/after hooks should ensure enableSystemPac
failures can't leave the OS proxy set; wrap calls to enableSystemPac (and any
system-modifying setup) in a try/finally so disableSystemPac always runs on
error: modify the setup where startServers() and enableSystemPac() are invoked
(referencing startServers, enableSystemPac, disableSystemPac, stopServers) to
catch exceptions from enableSystemPac and call disableSystemPac in a finally
block, and ensure stopServers is awaited in the cleanup path as well so servers
are stopped whether setup succeeds or fails.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a06975e5-0a99-46af-8e95-afd91be54a47
📒 Files selected for processing (16)
packages/bruno-electron/src/ipc/network/cert-utils.jspackages/bruno-electron/src/store/system-proxy.jspackages/bruno-electron/src/utils/proxy-util.jspackages/bruno-requests/src/network/system-proxy/index.spec.jspackages/bruno-requests/src/network/system-proxy/index.tspackages/bruno-requests/src/network/system-proxy/types.tspackages/bruno-requests/src/network/system-proxy/utils/linux.tspackages/bruno-requests/src/network/system-proxy/utils/macos.spec.tspackages/bruno-requests/src/network/system-proxy/utils/macos.tspackages/bruno-requests/src/network/system-proxy/utils/windows.tspackages/bruno-requests/src/utils/http-https-agents.tstests/proxy/system-pac/fixtures/collection/bruno.jsontests/proxy/system-pac/fixtures/collection/direct.brutests/proxy/system-pac/fixtures/collection/proxied.brutests/proxy/system-pac/init-user-data/preferences.jsontests/proxy/system-pac/system-pac-proxy.spec.ts
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
tests/proxy/system-pac/system-pac-proxy.spec.ts (1)
12-16:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAvoid hardcoding the macOS network service name.
Line 12 assumes
'Wi-Fi', which is brittle on hosts where the active service is named differently (e.g., Ethernet/Thunderbolt/custom labels). Prefer an env-configurable service name (or runtime detection) before invokingnetworksetup.Suggested patch
-const NETWORK_SERVICE = 'Wi-Fi'; +const NETWORK_SERVICE = process.env.BRUNO_TEST_NETWORK_SERVICE || 'Wi-Fi';🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/proxy/system-pac/system-pac-proxy.spec.ts` around lines 12 - 16, The test currently hardcodes the macOS network service name via the NETWORK_SERVICE constant and uses it in enableSystemPac(pacUrl), which breaks on machines where the active service is named differently; change this to read the service name from an environment variable (e.g., process.env.SYSTEM_PAC_NETWORK_SERVICE) with a sensible fallback (or implement runtime detection of the active network service) and use that value inside enableSystemPac; update references to NETWORK_SERVICE and ensure tests can override the env var to target different service names.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/proxy/system-pac/system-pac-proxy.spec.ts`:
- Around line 31-36: The teardown currently calls disableSystemPac() then awaits
stopServers(servers), but if disableSystemPac() throws the servers shutdown is
skipped; update the test.afterAll block (in system-pac-proxy.spec.ts) to ensure
stopServers always runs by wrapping the PAC reset in try/finally (e.g., await
disableSystemPac() inside try and in finally check/await stopServers(servers));
keep the function async and preserve existing null/undefined guard for servers.
---
Duplicate comments:
In `@tests/proxy/system-pac/system-pac-proxy.spec.ts`:
- Around line 12-16: The test currently hardcodes the macOS network service name
via the NETWORK_SERVICE constant and uses it in enableSystemPac(pacUrl), which
breaks on machines where the active service is named differently; change this to
read the service name from an environment variable (e.g.,
process.env.SYSTEM_PAC_NETWORK_SERVICE) with a sensible fallback (or implement
runtime detection of the active network service) and use that value inside
enableSystemPac; update references to NETWORK_SERVICE and ensure tests can
override the env var to target different service names.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d9c025ba-db71-4a92-8bec-d99acc8417ab
📒 Files selected for processing (2)
packages/bruno-requests/src/network/system-proxy/utils/macos.spec.tstests/proxy/system-pac/system-pac-proxy.spec.ts
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
tests/proxy/system-pac/system-pac-proxy.spec.ts (1)
12-16:⚠️ Potential issue | 🟠 Major | ⚡ Quick winHardcoded
NETWORK_SERVICEmakes this macOS test environment-dependentLine 12 assumes the service is always
Wi-Fi; this fails on hosts using different service names (e.g., Ethernet-only setups). Please resolve the service dynamically or allow explicit override via env var.Suggested patch
-const NETWORK_SERVICE = 'Wi-Fi'; +function resolveNetworkService() { + const fromEnv = process.env.BRUNO_NETWORK_SERVICE; + if (fromEnv) { + return fromEnv; + } + const output = execSync('networksetup -listallnetworkservices', { encoding: 'utf8' }); + const services = output + .split('\n') + .map((line) => line.trim()) + .filter((line) => line.length > 0 && !line.startsWith('*')); + if (services.includes('Wi-Fi')) { + return 'Wi-Fi'; + } + return services[0] || 'Wi-Fi'; +} + +const NETWORK_SERVICE = resolveNetworkService();Based on learnings: “Ensure tests are deterministic and reproducible. No randomness, timing dependencies, or environment-specific assumptions without explicit control.”
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/proxy/system-pac/system-pac-proxy.spec.ts` around lines 12 - 16, The test hardcodes NETWORK_SERVICE = 'Wi-Fi' used by enableSystemPac(pacUrl) which breaks on machines with different network service names; update enableSystemPac to first check an override env var (e.g., PROCESS_ENV_NETWORK_SERVICE) and if not present, discover the active macOS network service dynamically (e.g., parse output of networksetup -listallnetworkservices or system_profiler commands) and fall back to a safe default, then call execSync with the resolved service name; ensure the symbol NETWORK_SERVICE is replaced by this resolved value and add a clear error message if no service can be detected.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/proxy/system-pac/system-pac-proxy.spec.ts`:
- Around line 18-20: The teardown currently forces PAC off via
disableSystemPac(), which overwrites existing host proxy settings; modify the
test to read and store the original PAC state and PAC URL at setup (e.g., in
beforeAll), and in afterAll restore the saved values instead of always turning
PAC off—use the same helper functions (disableSystemPac) or add a
restoreSystemPac(originalState, originalUrl) helper to reapply the previous
on/off state and URL; update any other places noted (lines ~31-39) that mutate
PAC so they also save the original state before changing it and restore it in
teardown.
---
Duplicate comments:
In `@tests/proxy/system-pac/system-pac-proxy.spec.ts`:
- Around line 12-16: The test hardcodes NETWORK_SERVICE = 'Wi-Fi' used by
enableSystemPac(pacUrl) which breaks on machines with different network service
names; update enableSystemPac to first check an override env var (e.g.,
PROCESS_ENV_NETWORK_SERVICE) and if not present, discover the active macOS
network service dynamically (e.g., parse output of networksetup
-listallnetworkservices or system_profiler commands) and fall back to a safe
default, then call execSync with the resolved service name; ensure the symbol
NETWORK_SERVICE is replaced by this resolved value and add a clear error message
if no service can be detected.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 656842da-3471-41da-b9a8-b949090cc651
📒 Files selected for processing (1)
tests/proxy/system-pac/system-pac-proxy.spec.ts
b790838 to
f8e436b
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/bruno-electron/src/utils/proxy-util.js`:
- Around line 121-124: The PAC branch builds requestConfig.httpAgent for HTTPS
proxy but omits TLS options; update the call that creates the httpAgent (where
scheme, proxyUri and getOrCreateHttpAgent/HttpProxyAgent are used) to include
tlsOptions (CA, cert/key, rejectUnauthorized, etc.) the same way the manual
proxy path does—i.e., pass tlsOptions into the options for getOrCreateHttpAgent
when scheme === 'https' so proxy certificate validation and client certs are
applied; leave the httpsAgent creation
(getOrCreateHttpsAgent/PatchedHttpsProxyAgent) unchanged.
In `@tests/proxy/system-pac/system-pac-proxy.spec.ts`:
- Around line 14-19: The tests use execSync with shell-interpolated commands in
enableSystemPac and disableSystemPac; replace those with execFileSync calls and
pass the program ("networksetup") and an arguments array instead of a shell
string to avoid interpolation issues—e.g., in enableSystemPac call
execFileSync("networksetup", ["-setautoproxyurl", NETWORK_SERVICE, pacUrl"]) and
in disableSystemPac call execFileSync("networksetup", ["-setautoproxystate",
NETWORK_SERVICE, "off"]) so NETWORK_SERVICE and pacUrl are passed as separate
args.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3cb960a5-178f-4c08-b62e-0fded91ead73
📒 Files selected for processing (17)
packages/bruno-app/src/components/Preferences/ProxySettings/SystemProxy/index.jspackages/bruno-electron/src/ipc/network/cert-utils.jspackages/bruno-electron/src/store/system-proxy.jspackages/bruno-electron/src/utils/proxy-util.jspackages/bruno-requests/src/network/system-proxy/index.spec.jspackages/bruno-requests/src/network/system-proxy/index.tspackages/bruno-requests/src/network/system-proxy/types.tspackages/bruno-requests/src/network/system-proxy/utils/linux.tspackages/bruno-requests/src/network/system-proxy/utils/macos.spec.tspackages/bruno-requests/src/network/system-proxy/utils/macos.tspackages/bruno-requests/src/network/system-proxy/utils/windows.tspackages/bruno-requests/src/utils/http-https-agents.tstests/proxy/system-pac/fixtures/collection/bruno.jsontests/proxy/system-pac/fixtures/collection/direct.brutests/proxy/system-pac/fixtures/collection/proxied.brutests/proxy/system-pac/init-user-data/preferences.jsontests/proxy/system-pac/system-pac-proxy.spec.ts
✅ Files skipped from review due to trivial changes (3)
- packages/bruno-requests/src/network/system-proxy/types.ts
- tests/proxy/system-pac/init-user-data/preferences.json
- tests/proxy/system-pac/fixtures/collection/bruno.json
🚧 Files skipped from review as they are similar to previous changes (12)
- packages/bruno-electron/src/store/system-proxy.js
- packages/bruno-requests/src/network/system-proxy/index.spec.js
- packages/bruno-requests/src/network/system-proxy/utils/macos.ts
- packages/bruno-electron/src/ipc/network/cert-utils.js
- tests/proxy/system-pac/fixtures/collection/proxied.bru
- packages/bruno-requests/src/network/system-proxy/index.ts
- packages/bruno-app/src/components/Preferences/ProxySettings/SystemProxy/index.js
- packages/bruno-requests/src/network/system-proxy/utils/linux.ts
- tests/proxy/system-pac/fixtures/collection/direct.bru
- packages/bruno-requests/src/network/system-proxy/utils/macos.spec.ts
- packages/bruno-requests/src/network/system-proxy/utils/windows.ts
- packages/bruno-requests/src/utils/http-https-agents.ts
|
A nit for another ticket |
Description
Bruno supports PAC proxy resolution when explicitly configured in preferences, but in System proxy mode, OS-level PAC configuration is silently ignored.
JIRA
Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit
New Features
Tests