disable modsecurity on error page (#8202)
* disable modsecurity on error page * fix modsecurity error pages test * fix variable in nginx template * disable modsecurity on all internal locations * fix pipeline checks for gofmt Signed-off-by: Florian Michel <florianmichel@hotmail.de>
This commit is contained in:
parent
3230638160
commit
ee50e38b44
2 changed files with 27 additions and 9 deletions
|
@ -1277,15 +1277,17 @@ func proxySetHeader(loc interface{}) string {
|
||||||
|
|
||||||
// buildCustomErrorDeps is a utility function returning a struct wrapper with
|
// buildCustomErrorDeps is a utility function returning a struct wrapper with
|
||||||
// the data required to build the 'CUSTOM_ERRORS' template
|
// the data required to build the 'CUSTOM_ERRORS' template
|
||||||
func buildCustomErrorDeps(upstreamName string, errorCodes []int, enableMetrics bool) interface{} {
|
func buildCustomErrorDeps(upstreamName string, errorCodes []int, enableMetrics bool, modsecurityEnabled bool) interface{} {
|
||||||
return struct {
|
return struct {
|
||||||
UpstreamName string
|
UpstreamName string
|
||||||
ErrorCodes []int
|
ErrorCodes []int
|
||||||
EnableMetrics bool
|
EnableMetrics bool
|
||||||
|
ModsecurityEnabled bool
|
||||||
}{
|
}{
|
||||||
UpstreamName: upstreamName,
|
UpstreamName: upstreamName,
|
||||||
ErrorCodes: errorCodes,
|
ErrorCodes: errorCodes,
|
||||||
EnableMetrics: enableMetrics,
|
EnableMetrics: enableMetrics,
|
||||||
|
ModsecurityEnabled: modsecurityEnabled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -656,7 +656,7 @@ http {
|
||||||
{{ $cfg.ServerSnippet }}
|
{{ $cfg.ServerSnippet }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ template "CUSTOM_ERRORS" (buildCustomErrorDeps "upstream-default-backend" $cfg.CustomHTTPErrors $all.EnableMetrics) }}
|
{{ template "CUSTOM_ERRORS" (buildCustomErrorDeps "upstream-default-backend" $cfg.CustomHTTPErrors $all.EnableMetrics $cfg.EnableModsecurity) }}
|
||||||
}
|
}
|
||||||
## end server {{ $server.Hostname }}
|
## end server {{ $server.Hostname }}
|
||||||
|
|
||||||
|
@ -872,11 +872,17 @@ stream {
|
||||||
{{/* definition of templates to avoid repetitions */}}
|
{{/* definition of templates to avoid repetitions */}}
|
||||||
{{ define "CUSTOM_ERRORS" }}
|
{{ define "CUSTOM_ERRORS" }}
|
||||||
{{ $enableMetrics := .EnableMetrics }}
|
{{ $enableMetrics := .EnableMetrics }}
|
||||||
|
{{ $modsecurityEnabled := .ModsecurityEnabled }}
|
||||||
{{ $upstreamName := .UpstreamName }}
|
{{ $upstreamName := .UpstreamName }}
|
||||||
{{ range $errCode := .ErrorCodes }}
|
{{ range $errCode := .ErrorCodes }}
|
||||||
location @custom_{{ $upstreamName }}_{{ $errCode }} {
|
location @custom_{{ $upstreamName }}_{{ $errCode }} {
|
||||||
internal;
|
internal;
|
||||||
|
|
||||||
|
# Ensure that modsecurity will not run on custom error pages or they might be blocked
|
||||||
|
{{ if $modsecurityEnabled }}
|
||||||
|
modsecurity off;
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
proxy_intercept_errors off;
|
proxy_intercept_errors off;
|
||||||
|
|
||||||
proxy_set_header X-Code {{ $errCode }};
|
proxy_set_header X-Code {{ $errCode }};
|
||||||
|
@ -1015,7 +1021,7 @@ stream {
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ range $errorLocation := (buildCustomErrorLocationsPerServer $server) }}
|
{{ range $errorLocation := (buildCustomErrorLocationsPerServer $server) }}
|
||||||
{{ template "CUSTOM_ERRORS" (buildCustomErrorDeps $errorLocation.UpstreamName $errorLocation.Codes $all.EnableMetrics) }}
|
{{ template "CUSTOM_ERRORS" (buildCustomErrorDeps $errorLocation.UpstreamName $errorLocation.Codes $all.EnableMetrics $all.Cfg.EnableModsecurity) }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ buildMirrorLocations $server.Locations }}
|
{{ buildMirrorLocations $server.Locations }}
|
||||||
|
@ -1048,6 +1054,11 @@ stream {
|
||||||
opentracing_propagate_context;
|
opentracing_propagate_context;
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
# Ensure that modsecurity will not run on an internal location as this is not accessible from outside
|
||||||
|
{{ if $all.Cfg.EnableModsecurity }}
|
||||||
|
modsecurity off;
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
{{ if $externalAuth.AuthCacheKey }}
|
{{ if $externalAuth.AuthCacheKey }}
|
||||||
set $tmp_cache_key '{{ $server.Hostname }}{{ $authPath }}{{ $externalAuth.AuthCacheKey }}';
|
set $tmp_cache_key '{{ $server.Hostname }}{{ $authPath }}{{ $externalAuth.AuthCacheKey }}';
|
||||||
set $cache_key '';
|
set $cache_key '';
|
||||||
|
@ -1158,6 +1169,11 @@ stream {
|
||||||
|
|
||||||
add_header Set-Cookie $auth_cookie;
|
add_header Set-Cookie $auth_cookie;
|
||||||
|
|
||||||
|
# Ensure that modsecurity will not run on an internal location as this is not accessible from outside
|
||||||
|
{{ if $all.Cfg.EnableModsecurity }}
|
||||||
|
modsecurity off;
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
return 302 {{ buildAuthSignURL $externalAuth.SigninURL $externalAuth.SigninURLRedirectParam }};
|
return 302 {{ buildAuthSignURL $externalAuth.SigninURL $externalAuth.SigninURLRedirectParam }};
|
||||||
}
|
}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
Loading…
Reference in a new issue