meteor/livedata/server/livedata_server.js
function () {
    var self = this;

    // For the reported client address for a connection to be correct,
    // the developer must set the HTTP_FORWARDED_COUNT environment
    // variable to an integer representing the number of hops they
    // expect in the `x-forwarded-for` header. E.g., set to "1" if the
    // server is behind one proxy.
    //
    // This could be computed once at startup instead of every time.
    var httpForwardedCount = parseInt(process.env['HTTP_FORWARDED_COUNT']) || 0;

    if (httpForwardedCount === 0)
      return self.socket.remoteAddress;

    var forwardedFor = self.socket.headers["x-forwarded-for"];
    if (! _.isString(forwardedFor))
      return null;
    forwardedFor = forwardedFor.trim().split(/\s*,\s*/);

    // Typically the first value in the `x-forwarded-for` header is
    // the original IP address of the client connecting to the first
    // proxy.  However, the end user can easily spoof the header, in
    // which case the first value(s) will be the fake IP address from
    // the user pretending to be a proxy reporting the original IP
    // address value.  By counting HTTP_FORWARDED_COUNT back from the
    // end of the list, we ensure that we get the IP address being
    // reported by *our* first proxy.

    if (httpForwardedCount < 0 || httpForwardedCount > forwardedFor.length)
      return null;

    return forwardedFor[forwardedFor.length - httpForwardedCount];
  }
function () {
    var self = this;

    // For the reported client address for a connection to be correct,
    // the developer must set the HTTP_FORWARDED_COUNT environment
    // variable to an integer representing the number of hops they
    // expect in the `x-forwarded-for` header. E.g., set to "1" if the
    // server is behind one proxy.
    //
    // This could be computed once at startup instead of every time.
    var httpForwardedCount = parseInt(process.env['HTTP_FORWARDED_COUNT']) || 0;

    if (httpForwardedCount === 0)
      return self.socket.remoteAddress;

    var forwardedFor = self.socket.headers["x-forwarded-for"];
    if (! _.isString(forwardedFor))
      return null;
    forwardedFor = forwardedFor.trim().split(/\s*,\s*/);

    // Typically the first value in the `x-forwarded-for` header is
    // the original IP address of the client connecting to the first
    // proxy.  However, the end user can easily spoof the header, in
    // which case the first value(s) will be the fake IP address from
    // the user pretending to be a proxy reporting the original IP
    // address value.  By counting HTTP_FORWARDED_COUNT back from the
    // end of the list, we ensure that we get the IP address being
    // reported by *our* first proxy.

    if (httpForwardedCount < 0 || httpForwardedCount > forwardedFor.length)
      return null;

    return forwardedFor[forwardedFor.length - httpForwardedCount];
  }
function ( ) { var self = this ; // For the reported client address for a connection to be correct, // the developer must set the HTTP_FORWARDED_COUNT environment // variable to an integer representing the number of hops they // expect in the `x-forwarded-for` header. E.g., set to "1" if the // server is behind one proxy. // // This could be computed once at startup instead of every time. var httpForwardedCount = parseInt ( process . env [ 'HTTP_FORWARDED_COUNT' ] ) || 0 ; if ( httpForwardedCount === 0 ) return self . socket . remoteAddress ; var forwardedFor = self . socket . headers [ "x-forwarded-for" ] ; if ( ! _ . isString ( forwardedFor ) ) return null ; forwardedFor = forwardedFor . trim ( ) . split ( / \s*,\s* / ) ; // Typically the first value in the `x-forwarded-for` header is // the original IP address of the client connecting to the first // proxy.  However, the end user can easily spoof the header, in // which case the first value(s) will be the fake IP address from // the user pretending to be a proxy reporting the original IP // address value.  By counting HTTP_FORWARDED_COUNT back from the // end of the list, we ensure that we get the IP address being // reported by *our* first proxy. if ( httpForwardedCount < 0 || httpForwardedCount > forwardedFor . length ) return null ; return forwardedFor [ forwardedFor . length - httpForwardedCount ] ; }
Determine the remote client's IP address, based on the HTTP_FORWARDED_COUNT environment variable representing how many proxies the server is behind.
Determine the remote client s IP address based on the HTTP_FORWARDED_COUNT environment variable representing how many proxies the server is behind .