@@ 60,6 60,7 @@ const (
type AuthContext struct {
AuthMethod string
+ IPAddress string
// Only filled out for non-anonymous authentication
UserID int
@@ 310,6 311,23 @@ func internalAuth(internalNet []*net.IPNet, payload []byte,
auth.InternalAuth = internalAuth
+ auth.IPAddress = r.RemoteAddr
+ var route []string
+ for _, val := range r.Header.Values("X-Forwarded-For") {
+ route = append(route, strings.Split(val, ",")...)
+ }
+ for _, val := range route {
+ ip := net.ParseIP(val)
+ if ip == nil {
+ continue
+ }
+ if ip.IsPrivate() {
+ continue
+ }
+ auth.IPAddress = ip.String()
+ break
+ }
+
ctx := context.WithValue(r.Context(), userCtxKey, auth)
r = r.WithContext(ctx)
next.ServeHTTP(w, r)