From 3b061cda89db0a8490ff29dd01eb35db8ce35e30 Mon Sep 17 00:00:00 2001 From: naman-bruno Date: Wed, 26 Mar 2025 15:41:29 +0530 Subject: [PATCH] Fix: agentOptions not passing properly to baseAgent --- .../bruno-electron/src/utils/proxy-util.js | 65 +++++++++++++++---- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/packages/bruno-electron/src/utils/proxy-util.js b/packages/bruno-electron/src/utils/proxy-util.js index 8c4766b24..52034983e 100644 --- a/packages/bruno-electron/src/utils/proxy-util.js +++ b/packages/bruno-electron/src/utils/proxy-util.js @@ -87,10 +87,46 @@ class PatchedHttpsProxyAgent extends HttpsProxyAgent { function createTimelineAgentClass(BaseAgentClass) { return class extends BaseAgentClass { constructor(options, timeline) { - super(options); - this.timeline = Array.isArray(timeline) ? timeline : []; - this.alpnProtocols = options.ALPNProtocols || ['h2', 'http/1.1']; - this.caProvided = !!options.ca; + // For proxy agents, the first argument is the proxy URI and the second is options + if (options.proxy || typeof options === 'string') { + const proxyUri = typeof options === 'string' ? options : options.proxy; + const agentOptions = typeof options === 'string' ? {} : { ...options }; + delete agentOptions.proxy; + + // Ensure TLS options are properly set + const tlsOptions = { + ...agentOptions, + rejectUnauthorized: agentOptions.rejectUnauthorized !== undefined ? agentOptions.rejectUnauthorized : true, + }; + super(proxyUri, tlsOptions); + this.timeline = Array.isArray(timeline) ? timeline : []; + this.alpnProtocols = tlsOptions.ALPNProtocols || ['h2', 'http/1.1']; + this.caProvided = !!tlsOptions.ca; + + // Log TLS verification status + this.timeline.push({ + timestamp: new Date(), + type: 'info', + message: `SSL validation: ${tlsOptions.rejectUnauthorized ? 'enabled' : 'disabled'}`, + }); + } else { + // This is a regular HTTPS agent case + const tlsOptions = { + ...options, + rejectUnauthorized: options.rejectUnauthorized !== undefined ? options.rejectUnauthorized : true, + }; + super(tlsOptions); + this.timeline = Array.isArray(timeline) ? timeline : []; + this.alpnProtocols = options.ALPNProtocols || ['h2', 'http/1.1']; + this.caProvided = !!options.ca; + + // Log TLS verification status + this.timeline.push({ + timestamp: new Date(), + type: 'info', + message: `SSL validation: ${tlsOptions.rejectUnauthorized ? 'enabled' : 'disabled'}`, + }); + } } createConnection(options, callback) { @@ -257,6 +293,12 @@ function setupProxyAgents({ interpolationOptions, timeline, }) { + // Ensure TLS options are properly set + const tlsOptions = { + ...httpsAgentRequestFields, + rejectUnauthorized: httpsAgentRequestFields.rejectUnauthorized !== undefined ? httpsAgentRequestFields.rejectUnauthorized : true, + }; + if (proxyMode === 'on') { const shouldProxy = shouldUseProxy(requestConfig.url, get(proxyConfig, 'bypassProxy', '')); if (shouldProxy) { @@ -279,20 +321,19 @@ function setupProxyAgents({ if (socksEnabled) { const TimelineSocksProxyAgent = createTimelineAgentClass(SocksProxyAgent); requestConfig.httpAgent = new TimelineSocksProxyAgent({ proxy: proxyUri }, timeline); - requestConfig.httpsAgent = new TimelineSocksProxyAgent({ proxy: proxyUri, ...httpsAgentRequestFields }, timeline); + requestConfig.httpsAgent = new TimelineSocksProxyAgent({ proxy: proxyUri, ...tlsOptions }, timeline); } else { - const TimelineHttpsProxyAgent = createTimelineAgentClass(HttpsProxyAgent); + const TimelineHttpsProxyAgent = createTimelineAgentClass(PatchedHttpsProxyAgent); requestConfig.httpAgent = new HttpProxyAgent(proxyUri); // For http, no need for timeline requestConfig.httpsAgent = new TimelineHttpsProxyAgent( - proxyUri, - { ...httpsAgentRequestFields }, + { proxy: proxyUri, ...tlsOptions }, timeline ); } } else { // If proxy should not be used, set default HTTPS agent const TimelineHttpsAgent = createTimelineAgentClass(https.Agent); - requestConfig.httpsAgent = new TimelineHttpsAgent(httpsAgentRequestFields, timeline); + requestConfig.httpsAgent = new TimelineHttpsAgent(tlsOptions, timeline); } } else if (proxyMode === 'system') { const { http_proxy, https_proxy, no_proxy } = preferencesUtil.getSystemProxyEnvVariables(); @@ -312,7 +353,7 @@ function setupProxyAgents({ const TimelineHttpsProxyAgent = createTimelineAgentClass(HttpsProxyAgent); requestConfig.httpsAgent = new TimelineHttpsProxyAgent( https_proxy, - { ...httpsAgentRequestFields }, + { ...tlsOptions }, timeline ); } @@ -321,11 +362,11 @@ function setupProxyAgents({ } } else { const TimelineHttpsAgent = createTimelineAgentClass(https.Agent); - requestConfig.httpsAgent = new TimelineHttpsAgent(httpsAgentRequestFields, timeline); + requestConfig.httpsAgent = new TimelineHttpsAgent(tlsOptions, timeline); } } else { const TimelineHttpsAgent = createTimelineAgentClass(https.Agent); - requestConfig.httpsAgent = new TimelineHttpsAgent(httpsAgentRequestFields, timeline); + requestConfig.httpsAgent = new TimelineHttpsAgent(tlsOptions, timeline); } }