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

https.Agent does not respect rejectUnauthorized option #10834

Open
jgoz opened this issue May 4, 2024 · 0 comments
Open

https.Agent does not respect rejectUnauthorized option #10834

jgoz opened this issue May 4, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jgoz
Copy link

jgoz commented May 4, 2024

What version of Bun is running?

1.1.7

What platform is your computer?

Darwin 23.4.0 arm64 arm

What steps can reproduce the bug?

const https = require('node:https');

const options = {
  hostname: 'self-signed.badssl.com',
  port: 443,
  path: '/',
  method: 'GET',
};
options.agent = new https.Agent({
  ...options,
  rejectUnauthorized: false, // <-- this should avoid self-signed cert errors
});

const req = https.request(options, res => {
  console.log('statusCode:', res.statusCode);
  console.log('headers:', res.headers);
  res.on('data', d => {
    console.log('received: ' + d.length);
  });
});

req.on('error', e => {
  console.error(e);
});
req.end();

What is the expected behavior?

Expected rejectUnauthorized to be respected and no error to be thrown. This is how NodeJS behaves.

What do you see instead?

Error:

DEPTH_ZERO_SELF_SIGNED_CERT: self signed certificate
 path: "https://self-signed.badssl.com/"

Additional information

Running the program with NODE_TLS_REJECT_UNAUTHORIZED="false" achieves the desired behavior, as does passing the option nested inside of a tls property on the request options (not the agent options):

const options = {
  hostname: 'self-signed.badssl.com',
  port: 443,
  path: '/',
  method: 'GET',
  tls: {
    rejectUnauthorized: false
  }
};
@jgoz jgoz added the bug Something isn't working label May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant