Posted by mindgame on September 17, 2008 at 9:44am
Issue Summary
In "includes/bootstrap.inc", function "ip_address":
Instead of
array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']))
shouldn't it be
trim(array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])))
because when the XFF header contains multiple addresses they are separated by ", ".
Same for D7.
Comments
#1
No RFC, but according to wikipedia:
So it indeed looks as if we should either explode using
', 'instead of','or wrap the array_pop in trim as per your suggestion.#2
Patch.
#3
Patch looks good. Maybe extend the code comment a bit? That wouldn't hurt.
#4
Rewrote the comment to provide some extra documentation/clarification.
#5
Committed to CVS HEAD. Thanks.
#6
Automatically closed -- issue fixed for 2 weeks with no activity.
#7
Why does ip_address() use the rightmost entry from X-Forwarded-For header? Isn't the purpose of ip_address() to get the end-user/client's IP address? The documentation for X-Forwarded-For on wikipedia seems to state that the client's IP is the first mentioned IP (leftmost) and any other servers that touch the request append their IPs to the end of the list (rightmost). Am I misunderstanding how X-Forwarded-For is used in this situation?
Selecting the rightmost IP is breaking our Drupal setup where our servers are behind a CDN that passes the client's IP as the first IP in the X-Forwarded-For header.
Also posted this question on http://drupal.org/node/258397 since they are newest issues I could find.
Thanks in advance