Skip to content

Commit

Permalink
added support for retrieving correct origin ip for requests coming fr…
Browse files Browse the repository at this point in the history
…om behind a proxy (nginx/apache2/cloudflare/azure)
  • Loading branch information
kgretzky committed Mar 1, 2024
1 parent e7a6866 commit 1b9cb59
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions core/http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,16 @@ func NewHttpProxy(hostname string, port int, cfg *Config, crt_db *CertDb, db *da
hiblue := color.New(color.FgHiBlue)

// handle ip blacklist
from_ip := req.RemoteAddr
if strings.Contains(from_ip, ":") {
from_ip = strings.SplitN(from_ip, ":", 2)[0]
from_ip := strings.SplitN(req.RemoteAddr, ":", 2)[0]

// handle proxy headers
proxyHeaders := []string{"X-Forwarded-For", "X-Real-IP", "X-Client-IP", "Connecting-IP", "True-Client-IP", "Client-IP"}
for _, h := range proxyHeaders {
origin_ip := req.Header.Get(h)
if origin_ip != "" {
from_ip = strings.SplitN(origin_ip, ":", 2)[0]
break
}
}

if p.cfg.GetBlacklistMode() != "off" {
Expand Down

0 comments on commit 1b9cb59

Please sign in to comment.