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.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 309586_XFF_spaces.patch | 1.19 KB | mr.baileys |
| #2 | 309586_XFF_spaces.patch | 685 bytes | mr.baileys |
Comments
Comment #1
mr.baileysNo 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.Comment #2
mr.baileysPatch.
Comment #3
dries commentedPatch looks good. Maybe extend the code comment a bit? That wouldn't hurt.
Comment #4
mr.baileysRewrote the comment to provide some extra documentation/clarification.
Comment #5
dries commentedCommitted to CVS HEAD. Thanks.
Comment #7
teastburn85 commentedWhy 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