commit 4b0742641963e92fa528f573d0f2ffc8a832006b
Author: Arlo Breault <[email protected]>
Date:   Tue Nov 19 11:44:07 2013 -0800

    X-Forwarded-For can be a list.
    
    Since the service is behind Apache, the remote IP is append to that
    header. However, if it has already be set, it becomes a list.
    
    This was reported in trac #10190.
---
 handlers.go |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/handlers.go b/handlers.go
index 9342ff8..f852a0a 100644
--- a/handlers.go
+++ b/handlers.go
@@ -12,6 +12,7 @@ import (
        "regexp"
        "strconv"
        "time"
+       "strings"
 )
 
 // page model
@@ -44,7 +45,11 @@ func RootHandler(Layout *template.Template, Exits *Exits, 
domain *gettext.Domain
 
                // get remote ip
                host := r.Header.Get("X-Forwarded-For")
-               if len(host) == 0 {
+               if len(host) > 0 {
+                       parts := strings.Split(host, ",")
+                       // apache will append the remote address
+                       host = strings.TrimSpace(parts[len(parts) - 1]) 
+               } else {
                        host, _, err = net.SplitHostPort(r.RemoteAddr)
                }
 

_______________________________________________
tor-commits mailing list
[email protected]
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to