Zoltán Tudlik
Zoltán Tudlik

Reputation: 13

Firebase reverse dns lookup ENOTFOUND error node.js dns

Hello Stackoverflow community! :)

I have a cloud function running on Firebase, which serves as an API and there is another server (fitbit.com), which occasionally POSTs data to my server.

As one of the security features, I'd like to do a Forward-Confirmed Reverse DNS, which is basically the following:

  1. I receive a POST on an endpoint from IP 169.45.142.104.
  2. I do a reverse DNS lookup to retrieve the hostname of the server.
  3. Verify that this returns a subdomain of fitbit.com (the IP in the example should resolve into ['api-169-45-141-216.fitbit.com']).
  4. Then, I do a DNS lookup on that hostname and verify if it resolves to the IP address of the original request.

Here's the source code written for node v6.11.1 (it's in a Util class.. :))

static fcrDns(ipAddress, cb) {
        const reverse = Q.denodeify(dns.reverse);
        const resolve4 = Q.denodeify(dns.resolve4);
        return reverse(ipAddress).then(hostNames => {
            console.log("hostNames: ", hostNames);

            if (!hostNames.every(SecurityUtils._isFitbitSubDomain)) {
                return Promise.reject("Hostname did not end with .fitbit.com");
            } else {
                return Promise.all([...hostNames.map(hostName => {
                    return resolve4(hostName)
                        .then(resolvedAddresses => {
                            if (resolvedAddresses.every(address => address === ipAddress)) {
                                return Promise.resolve(true);
                            } else {
                                return Promise.reject("Resolved address did not equal to initial IP address");
                            }
                        })
                })]);
            }
        });
    }

    static _isFitbitSubDomain(hostName) {
        return hostName.endsWith(".fitbit.com");
    };

Now, the problem is: this works perfectly if I do firebase serve --only functions on localhost, both on windows and linux hosts.

However, once it's deployed to Firebase and executed, I get the following error:

{ Error: getHostByAddr ENOTFOUND 169.45.142.104
    at errnoException (dns.js:28:10)
    at QueryReqWrap.onresolve [as oncomplete] (dns.js:219:19)
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getHostByAddr',
  hostname: '169.45.142.104' }

Which, as far as I understood node's source code it means that it could not perform reverse IP lookup.

However, as I've tested, resolving the hostname works properly.

Might there be a server setting, which could prevent doing reverse dns lookup, but allows resolving?

Upvotes: 1

Views: 1164

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317712

I talked to the Cloud Functions backend team, and they currently don't allow reverse DNS lookups. This is something that could be changed, so I will encourage you to file a feature request with the details of why this is important to you. Also provide a link to this issue on SO.

EDIT: It looks like the change was made to allow this, but it's not clear to me if it's already available, or when it will be made available.

Upvotes: 1

Related Questions