diff --git a/server/server.go b/server/server.go index 5e88335..295fa92 100644 --- a/server/server.go +++ b/server/server.go @@ -127,10 +127,23 @@ func (s *Server) onionPath(name string) string { } func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { - r.Header.Set("X-Forwarded-For", r.RemoteAddr) + r.Header.Del("X-Forwarded-For") + + if r.Header.Get("X-Tor2web") != "" { + http.Error(w, "tor2web proxy use is not allowed", 400) + return + } + + host, _, err := net.SplitHostPort(r.RemoteAddr) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + r.Header.Set("X-Forwarded-For", host) + r.Header.Set("X-Remote-IP", host) r.Header.Set("X-Request-Ingress", time.Now().String()) - if r.RequestURI == rpc.DefaultRPCPath { + if r.RequestURI == rpc.DefaultRPCPath && r.Host == "127.0.0.1:"+s.cfg.WebPort { s.rpcS.ServeHTTP(w, r) return }