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

Created on 18 Sep 2015  ·  12Comments  ·  Source: request/request

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?

Most helpful comment

This stuff is horrible

All 12 comments

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

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?

Have you tried setting the rejectUnauthorized variable to false?

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

        })```

``````

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

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.

This stuff is horrible

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

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

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.

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.

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

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 .

Was this page helpful?
0 / 5 - 0 ratings