check / check (push) Failing after 1m42s
Each heuristic that refuses a request sets the status on its verdict. check copies it into the refusal, or in observe mode notes it, and no longer works the status out from the action. refusalLimit takes the status from that verdict instead of from a switch over the action. Model: opus-5-5
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package waf
|
|
|
|
// The heuristic countries. It reads SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES and
|
|
// SWW_WAF_BAN_RESPONSE.
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"time"
|
|
|
|
"sneak.berlin/go/smallwebwaf/internal/config"
|
|
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
|
)
|
|
|
|
// countries refuses a request when SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES is set and
|
|
// does not hold the client's country as it was looked up. A client without a
|
|
// country, or whose country cannot be found, is refused. It refuses with
|
|
// SWW_WAF_BAN_RESPONSE. Its figures are the country and the setting that
|
|
// refused it.
|
|
type countries struct {
|
|
allowed []string // SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES
|
|
banResponse int // SWW_WAF_BAN_RESPONSE
|
|
}
|
|
|
|
func (countries) name() string { return "countries" }
|
|
|
|
func (c countries) check(
|
|
_ context.Context,
|
|
rq *request,
|
|
_ time.Time,
|
|
) *verdict {
|
|
allowed := c.allowed
|
|
country := rq.lookupAnswer.Country
|
|
|
|
if len(allowed) == 0 || slices.Contains(allowed, country) {
|
|
return nil
|
|
}
|
|
|
|
return &verdict{
|
|
action: requestlog.ActionCountryDenied,
|
|
status: c.banResponse,
|
|
figures: map[string]any{
|
|
"country": country,
|
|
"setting": config.ExclusivelyAllowedCountriesSetting,
|
|
},
|
|
}
|
|
}
|