7

I have an Azure function written on node.js. How could I retrieved an IP address of a client that called the function?

What I've found so far:

  1. An answer to the same question, but using C#.
  2. It is possible to read it from headers:

    module.exports = function (context, req) {
        var ip = req.headers['x-forwarded-for']    
    }
    

Is it reliable to get the ip this way, since it can be easily changed on the way to the function?

Eskandar
  • 113
  • 1
  • 7

2 Answers2

2

Yes it is reliable, because Azure web server will overwrite x-forwarded-for as it knows it is forwarding from load balancer.

Akash Kava
  • 39,066
  • 20
  • 121
  • 167
-1

If you're using express, consider setting app.set('trust proxy');

For more information, check the express manual page on 'Express behing proxies'

Melle
  • 7,639
  • 1
  • 30
  • 31