mirror of
https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin.git
synced 2026-07-21 19:48:59 +02:00
Fix nil trusted checker
This commit is contained in:
+26
-12
@@ -93,12 +93,20 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h
|
|||||||
logger.Init(config.LogLevel)
|
logger.Init(config.LogLevel)
|
||||||
err := validateParams(config)
|
err := validateParams(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Info(fmt.Sprintf("%w", err))
|
logger.Info(err.Error())
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
checker, _ := ip.NewChecker(config.ForwardedHeadersTrustedIPs)
|
checker, err := ip.NewChecker(config.ForwardedHeadersTrustedIPs)
|
||||||
|
if err != nil {
|
||||||
|
logger.Debug("Checker == nil")
|
||||||
|
logger.Debug(err.Error())
|
||||||
|
}
|
||||||
checkerTrusted, err := ip.NewChecker(config.TrustedIPs)
|
checkerTrusted, err := ip.NewChecker(config.TrustedIPs)
|
||||||
|
if err != nil {
|
||||||
|
logger.Debug("CheckerTrusted == nil")
|
||||||
|
logger.Debug(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
bouncer := &Bouncer{
|
bouncer := &Bouncer{
|
||||||
next: next,
|
next: next,
|
||||||
@@ -150,23 +158,29 @@ func (bouncer *Bouncer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||||||
// Here we check for the trusted IPs in the customHeader
|
// Here we check for the trusted IPs in the customHeader
|
||||||
remoteHost, err := ip.GetRemoteIP(req, bouncer.poolStrategyTrusted, bouncer.customHeader)
|
remoteHost, err := ip.GetRemoteIP(req, bouncer.poolStrategyTrusted, bouncer.customHeader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Info(fmt.Sprintf("%w", err))
|
logger.Info(err.Error())
|
||||||
bouncer.next.ServeHTTP(rw, req)
|
bouncer.next.ServeHTTP(rw, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
trusted, err := bouncer.CheckerTrusted.Contains(remoteHost)
|
logger.Debug(fmt.Sprintf("ServeHTTP ip:%v", remoteHost))
|
||||||
if err != nil {
|
if bouncer.CheckerTrusted == nil {
|
||||||
logger.Info(fmt.Sprintf("%w", err))
|
logger.Debug("CheckerTrusted == nil")
|
||||||
return
|
} else {
|
||||||
}
|
trusted, err := bouncer.CheckerTrusted.Contains(remoteHost)
|
||||||
// if our IP is in the trusted list we bypass the next checks
|
if err != nil {
|
||||||
if trusted {
|
logger.Info(err.Error())
|
||||||
bouncer.next.ServeHTTP(rw, req)
|
return
|
||||||
|
}
|
||||||
|
// if our IP is in the trusted list we bypass the next checks
|
||||||
|
if trusted {
|
||||||
|
bouncer.next.ServeHTTP(rw, req)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here we get the IP from the trusted header customHeader
|
// Here we get the IP from the trusted header customHeader
|
||||||
remoteHost, err = ip.GetRemoteIP(req, bouncer.poolStrategy, bouncer.customHeader)
|
remoteHost, err = ip.GetRemoteIP(req, bouncer.poolStrategy, bouncer.customHeader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Info(fmt.Sprintf("%w", err))
|
logger.Info(err.Error())
|
||||||
bouncer.next.ServeHTTP(rw, req)
|
bouncer.next.ServeHTTP(rw, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user