Skip to content

Commit

Permalink
api/auth: make getting the remote IP into its own helper
Browse files Browse the repository at this point in the history
  • Loading branch information
thatoddmailbox committed Mar 28, 2024
1 parent 60d0f44 commit 800fb83
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,19 @@ func GetSessionInfo(r *http.Request) auth.SessionInfo {
return auth.GetSession(cookie.Value)
}

func isInternalRequest(r *http.Request) bool {
func getRequestRemoteAddr(r *http.Request) string {
remoteAddr := r.RemoteAddr
if config.GetCurrent().Server.ReverseProxyHeader != "" {
if r.Header.Get(config.GetCurrent().Server.ReverseProxyHeader) != "" {
header := strings.Split(r.Header.Get(config.GetCurrent().Server.ReverseProxyHeader), ",")
remoteAddr = strings.TrimSpace(header[len(header)-1])
}
}
return remoteAddr
}

func isInternalRequest(r *http.Request) bool {
remoteAddr := getRequestRemoteAddr(r)

if strings.Split(remoteAddr, ":")[0] == "127.0.0.1" || strings.HasPrefix(remoteAddr, "[::1]") {
return true
Expand Down

0 comments on commit 800fb83

Please sign in to comment.