mirror of
https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin.git
synced 2026-07-21 11:38:59 +02:00
✨ 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:
co-authored by
maxlerebourg
parent
21895fbb9d
commit
1c1672c856
+8
-2
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user