Consider 502, 503 and 504 as unavaible for appsec (#338)

* Consider 502, 503 and 504 as unavaible for appsec

Fixes #337

*  add test and the function isReverseProxyError

---------

Co-authored-by: maxlerebourg <maxlerebourg@gmail.com>
This commit is contained in:
Daniel Berteaud
2026-06-30 22:03:06 +02:00
committed by GitHub
co-authored by maxlerebourg
parent 21895fbb9d
commit 1c1672c856
4 changed files with 45 additions and 6 deletions
+8 -2
View File
@@ -677,6 +677,12 @@ func handleStreamCache(bouncer *Bouncer) error {
return nil
}
func isReverseProxyError(statusCode int) bool {
return statusCode == http.StatusBadGateway ||
statusCode == http.StatusServiceUnavailable ||
statusCode == http.StatusGatewayTimeout
}
func crowdsecQuery(bouncer *Bouncer, stringURL string, data []byte) ([]byte, error) {
var req *http.Request
if len(data) > 0 {
@@ -688,7 +694,7 @@ func crowdsecQuery(bouncer *Bouncer, stringURL string, data []byte) ([]byte, err
req.Header.Set("User-Agent", "Crowdsec-Bouncer-Traefik-Plugin/"+pluginVersion)
res, err := bouncer.httpClient.Do(req)
if err != nil {
if err != nil || isReverseProxyError(res.StatusCode) {
return nil, fmt.Errorf("crowdsecQuery:unreachable url:%s %w", stringURL, err)
}
defer func() {
@@ -752,7 +758,7 @@ func appsecQuery(bouncer *Bouncer, ip string, httpReq *http.Request) error {
req.Header.Set("User-Agent", "Crowdsec-Bouncer-Traefik-Plugin/"+pluginVersion)
res, err := bouncer.httpAppsecClient.Do(req)
if err != nil {
if err != nil || isReverseProxyError(res.StatusCode) {
bouncer.log.Error("appsecQuery:unreachable")
if bouncer.appsecUnreachableBlock {
return fmt.Errorf("appsecQuery:unreachable %w", err)