question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proxy with self-signed cert not accepted (rejectUnauthorized=false not being passed to tunnel-agent)

See original GitHub issue

Summary

When using request to CONNECT to an explicit proxy that had a self-signed cert, the request produced this error:

{ Error: tunneling socket could not be established, cause=self signed certificate
    at ClientRequest.onError (/nodeApp/node_modules/tunnel-agent/index.js:178:17)
    at ClientRequest.g (events.js:292:16)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:188:7)
    at TLSSocket.socketErrorListener (_http_client.js:310:9)
    at emitOne (events.js:96:13)
    at TLSSocket.emit (events.js:188:7)
    at emitErrorNT (net.js:1277:8)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9) code: 'ECONNRESET' }

I traced the problem to the code below at line 134 in tunnel-agent/index.js

debug('making CONNECT request')
  var connectReq = self.request(connectOptions)
  connectReq.useChunkedEncodingByDefault = false // for v0.6
  connectReq.once('response', onResponse) // for v0.6
  connectReq.once('upgrade', onUpgrade)   // for v0.6
  connectReq.once('connect', onConnect)   // for v0.7 or later
  connectReq.once('error', onError)
  connectReq.end()

The connectOptions at that point in the code did not contain the properties rejectUnauthorized or requestCert which were set to false in the request options object (even though headers set at the request object like Proxy-Authorization were passed all the way through);

Modifying the tunnel-agent module to hardcode the rejectUnauthorized and requestCert properties at this point in the code resolved the error.

version of request used was latest (2.81.1 )

So, it appears that somewhere the rejectUnauthorized and requestCert properties are being removed (or not copied over) such that they do not make there way down to the tunnel-agent module

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
vvocommented, Sep 20, 2017

I believe this is an API miss. When you want to ignore self-signed certificates while using an HTTPS proxy you have two types of certificates:

  1. the one of the website you want to make a request to
  2. the one of the https proxy you are using (like squid)

As for 1. the option used is request({rejectUnauthorized}), as for 2. today there’s no way to specify that you want to ignore the self signed certificate. For this it would mean being able to pass options to the CONNECT call here: https://github.com/request/tunnel-agent/blob/eb2b1b19e09ee0e6a2b54eb2612755731b7301dc/index.js#L122)

I propose to add a proxyConnectOptions attribute to request({}) and forward it to tunnel-agent (YAY! new option) to solve this.

What do you think?

0reactions
stale[bot]commented, Feb 27, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Certificate error when using HTTPS proxy with self-signed ...
It supports self-signed certificates without proxy or proxy with normal ... it seems that rejectUnauthorized is not respected when passing a ...
Read more >
Unable to verify leaf signature - Stack Overflow
It's not an issue with the application, but with the certificate which is signed by an intermediary CA. If you accept that fact...
Read more >
How to Resolve Certificate Errors in a NodeJS App with SSL ...
The above SSL errors are thrown because the client is not able to verify the trust chain of the self-signed server certificate sent...
Read more >
Use Certificates with HTTPS Proxy Content Inspection
A public CA certificate does not support the re-signing actions the HTTPS-proxy must perform when content inspection is enabled on your Firebox.
Read more >
TLS (SSL) | Node.js v19.3.0 Documentation
Creating a self-signed certificate using the OpenSSL command-line interface is ... rejectUnauthorized <boolean> If not false , the server certificate is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found