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

connecting to https endpoint and getting: Hostname/IP doesn't match certificate's altnames #1777

Closed
ddelizia opened this issue Sep 18, 2015 · 13 comments
Labels

Comments

@ddelizia
Copy link

I'm trying to connect to an external https REST service on heroku from my localhost with the following code:

request(
            {
                url: config.get('host') +req.originalUrl,
                method: req.method,
            }, function (error, response, body) {

            })

I get the following error in the callback:

Hostname/IP doesn't match certificate's altnames: "Host: localhost. is not in the cert's altnames: DNS:.herokuapp.com, DNS:herokuapp.com"
Host: localhost. is not in the cert's altnames: DNS:
.herokuapp.com, DNS:herokuapp.com

if I connect to the same service installed locally everything works correctly, so it should be related with https.

Any help?

@simov
Copy link
Member

simov commented Sep 23, 2015

What is the exact URL of your request config.get('host') +req.originalUrl?

@jperry
Copy link

jperry commented Oct 16, 2015

I am getting this also. I am using a self signed cert and I don't want to do hostname checking. I have this in my requests

agentOptions: {
        ca: fs.readFileSync('ca.cert.pem')
    }

How do you set ignoreHostname?

@strictlyd
Copy link

Have you tried setting the rejectUnauthorized variable to false?

                url: config.get('host') +req.originalUrl,
                method: req.method,
                rejectUnauthorized: false
            }, 
function (error, response, body) {

            })```

@justinmchase
Copy link

It would be nice if rejectUnauthorized: false was on the front page docs somewhere.

@josepmesteves
Copy link

Doesn't rejectUnauthorized: false make you accept any server certificate? If that is the case, I don't consider it a valid solution.
I would like to verify the server by making sure the certificate is signed by a trusted CA (in my case, it is my own CA). I don't want to silence the whole thing and make it insecure.

@rcronc
Copy link

rcronc commented Aug 29, 2017

This stuff is horrible

@tomonari-t
Copy link

You have to match server certification's CommonName to client's hostname.

@ChrisBellewVgw
Copy link

You have to match server certification's CommonName to client's hostname.

Why is that the case? Why does the client care about it's own hostname existing in the servers certificate? This is about the authentication of the server. Thanks

@pkopac
Copy link

pkopac commented May 23, 2019

FYI I got this error while I was forwarding requests, I used request({host: 'something.com'... headers: req.headers... What I didn't realize at first was that in the headers there was host: 'localhost', which was the culprit. I replaced it and now it verifies OK.

@rarebreed
Copy link

I believe I am hitting the same issue. I get the following error while using node 6.10.3 and request 2.88:

Error: Hostname/IP doesn't match certificate's altnames: "Host: https. is not in the cert's altnames:

I tracked this down to the node tls.js code. Somehow, "https." is being passed as the hostname by request down to node. If I set rejectUnauthorized to false, my code works. So I am passing in the correct hostname in the url.

@Curti-s
Copy link

Curti-s commented Nov 18, 2019

I believe this can be mitigated by using the api key provided by the target domain.

@alirayaneh
Copy link

FYI I got this error while I was forwarding requests, I used request({host: 'something.com'... headers: req.headers... What I didn't realize at first was that in the headers there was host: 'localhost', which was the culprit. I replaced it and now it verifies OK.

my problem solved . i have forget modify req.header and change host .

@stale
Copy link

stale bot commented Jun 4, 2021

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.

@stale stale bot added the stale label Jun 4, 2021
@stale stale bot closed this as completed Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests