Development

#2798: x_forwarded_for.patch

You must first sign up to be able to contribute.

Ticket #2798: x_forwarded_for.patch

File x_forwarded_for.patch, 2.7 kB (added by Nebelmann, 1 year ago)

This patch should do the trick. ->getForwardedRemoteAddress() is now ->getForwardedFor(), and returns an array or null.

  • test/unit/request/sfWebRequestTest.php

    old new  
    137137$_SERVER['REMOTE_ADDR'] = '127.0.0.1'; 
    138138$t->is($request->getRemoteAddress(), '127.0.0.1', '->getRemoteAddress() returns the remote address'); 
    139139 
    140 // ->getForwardedRemoteAddress() 
    141 $t->diag('->getForwardedRemoteAddress()'); 
    142 $t->is($request->getForwardedRemoteAddress(), null, '->getForwardedRemoteAddress() returns null if the request was not forwarded.'); 
    143 $_SERVER['HTTP_X_FORWARDED_FOR'] = '10.0.0.1'; 
    144 $t->is($request->getForwardedRemoteAddress(), '10.0.0.1', '->getForwardedRemoteAddress() returns the value from HTTP_X_FORWARDED_FOR'); 
     140// ->getForwardedFor() 
     141$t->diag('->getForwardedFor()'); 
     142$t->is($request->getForwardedFor(), null, '->getForwardedFor() returns null if the request was not forwarded.'); 
     143$_SERVER['HTTP_X_FORWARDED_FOR'] = '10.0.0.1, 10.0.0.2'; 
     144$t->is_deeply($request->getForwardedFor(), array('10.0.0.1', '10.0.0.2'), '->getForwardedFor() returns the value from HTTP_X_FORWARDED_FOR'); 
    145145 
    146146// methods 
    147147$t->diag('methods'); 
  • lib/request/sfWebRequest.class.php

    old new  
    766766  } 
    767767 
    768768  /** 
    769    * Returns the remote IP address for the request. 
     769   * Returns the remote IP address that made the request. 
    770770   * 
    771771   * @return string The remote IP address 
    772772   */ 
     
    778778  } 
    779779 
    780780  /** 
    781    * Returns the remote IP addressed after resolved from the forward. 
     781   * Returns an array containing a list of IPs, the first being the client address 
     782   * and the others the addresses of each proxy that passed the request. The address  
     783   * for the last proxy can be retrieved via getRemoteAddress(). 
    782784   * 
    783    * This is useful if you are testing to see if the user is behind a proxy. However, 
    784    * it should not be trusted
     785   * This method returns null if no proxy passed this request. Note that some proxies 
     786   * do not use this header, and act as if they were the client
    785787   * 
    786    * @return string|null The remote IP address resolved from a forward, null if none set 
     788   * @return string|null An array of IP from the client and the proxies that passed 
     789   * the request, or null if no proxy was used. 
    787790   */ 
    788   public function getForwardedRemoteAddress() 
     791  public function getForwardedFor() 
    789792  { 
    790793    $pathInfo = $this->getPathInfoArray(); 
    791794 
     
    794797      return null; 
    795798    } 
    796799 
    797     return $pathInfo['HTTP_X_FORWARDED_FOR']
     800    return split(', ', $pathInfo['HTTP_X_FORWARDED_FOR'])
    798801  } 
    799802 
    800803  /** 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.