Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: configurable rejectUnauthorized #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jan-molak
Copy link

@jan-molak jan-molak commented Aug 3, 2020

This change makes it possible to configure global-agent to ignore certificate errors when the request-specific configuration is not provided.

Problem

Axios does not allow its users to ignore SSL certificate errors, see axios/axios#535, axios/axios#1976 and other issues.

The recommended way around it is to configure Axios with an https.Agent with the appropriate setting:

const instance = axios.create({
  httpsAgent: new https.Agent({  
    rejectUnauthorized: false
  })
});

However, because of the way Axios determines whether to use a http.Agent or a https.Agent based on the protocol of the destination url, this only works if both the proxy and the target URL follow the same, HTTPS protocol.

To address the problem of Axios not supporting such protocol mismatch Global Agent could be used, but this then doesn't support ignoring certificate errors by means other than setting NODE_TLS_REJECT_UNAUTHORIZED to 0, which is a discouraged practice.

Proposed solution

Adding a new configuration option rejectUnauthorized to bootstrap routine would allow developers to provide a default setting for all the requests that go through global-agent, while allowing the more customisable HTTP clients like Sindre's got to still override it on a per-request basis:

bootstrap({ rejectUnauthorized: false });

const instance = axios.create();

Alternatives considered

While it is possible to force Global Agent to rejectUnauthorized by specifying NODE_TLS_REJECT_UNAUTHORIZED equal 0, I'd rather avoid that as this results in a warning emitted by Node.js:

(node:18596) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.

@jan-molak
Copy link
Author

Looks like the PR fails because of an intermittent timeout on one of the build runners?

@gajus gajus added the enhancement New feature or request label Sep 17, 2020
@roccomuso
Copy link

thanks for the PR, hope it gets reviewed and merged soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants