config: export the setting names waf logs (closes #448)
check / check (push) Failing after 2m44s
check / check (push) Failing after 2m44s
waf wrote eight setting names as string literals into log lines and ban notes, and config wrote each again where it reads the setting. A rename that missed one would log a setting that does not exist. config now exports a constant for each name, used by its reader and by waf. Model: opus-5-5
This commit is contained in:
1 parent
967ccdf75e
commit
0ac2ffe77b
3 files changed
+50
-29
No files matched your search
+17
-11
@@ -53,20 +53,20 @@ func (rq *request) limitPercentages() (percentage, percentage) {
|
||||
if country == "" && !rq.skippedLookupWait {
|
||||
unknown = percentage{
|
||||
cfg.UnknownCountryLimitPercent,
|
||||
"SWW_WAF_UNKNOWN_COUNTRY_LIMIT_PERCENT",
|
||||
config.UnknownCountryLimitPercentSetting,
|
||||
}
|
||||
}
|
||||
|
||||
fetched := percentage{percent: whole}
|
||||
if percent, listed := rq.h.lists.ASNLimitPercent(asn); listed {
|
||||
fetched = percentage{percent, "SWW_WAF_ASN_LIMIT_PERCENT_URL"}
|
||||
fetched = percentage{percent, config.ASNLimitPercentURLSetting}
|
||||
}
|
||||
|
||||
blocklisted := percentage{percent: whole}
|
||||
if rq.blocklisted && cfg.BlocklistAction == "limit" {
|
||||
blocklisted = percentage{
|
||||
cfg.BlocklistLimitPercent,
|
||||
"SWW_WAF_BLOCKLIST_ACTION",
|
||||
config.BlocklistActionSetting,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,20 +75,22 @@ func (rq *request) limitPercentages() (percentage, percentage) {
|
||||
cfg.DNSBLAbuseIPDBAction == "limit" {
|
||||
dnsblAbuseIPDBListed = percentage{
|
||||
cfg.DNSBLAbuseIPDBLimitPercent,
|
||||
"SWW_WAF_DNSBL_ABUSEIPDB_ACTION",
|
||||
config.DNSBLAbuseIPDBActionSetting,
|
||||
}
|
||||
}
|
||||
|
||||
const tagSetting = "SWW_WAF_TAG_LIMIT_PERCENT"
|
||||
|
||||
asnRequests := lowest(
|
||||
given(cfg.TagLimitPercent, asnTag(asn), tagSetting),
|
||||
given(
|
||||
cfg.TagLimitPercent,
|
||||
asnTag(asn),
|
||||
config.TagLimitPercentSetting,
|
||||
),
|
||||
fetched,
|
||||
)
|
||||
countryRequests := given(
|
||||
cfg.TagLimitPercent,
|
||||
countryTag(country),
|
||||
tagSetting,
|
||||
config.TagLimitPercentSetting,
|
||||
)
|
||||
|
||||
otherTags := percentage{percent: whole}
|
||||
@@ -97,7 +99,11 @@ func (rq *request) limitPercentages() (percentage, percentage) {
|
||||
if tag != asnTag(asn) && tag != countryTag(country) {
|
||||
otherTags = lowest(
|
||||
otherTags,
|
||||
given(cfg.TagLimitPercent, tag, tagSetting),
|
||||
given(
|
||||
cfg.TagLimitPercent,
|
||||
tag,
|
||||
config.TagLimitPercentSetting,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -107,7 +113,7 @@ func (rq *request) limitPercentages() (percentage, percentage) {
|
||||
asnBytes = given(
|
||||
cfg.ASNBytesLimitPercent,
|
||||
asn,
|
||||
"SWW_WAF_ASN_BYTES_LIMIT_PERCENT",
|
||||
config.ASNBytesLimitPercentSetting,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -115,7 +121,7 @@ func (rq *request) limitPercentages() (percentage, percentage) {
|
||||
countryBytes = given(
|
||||
cfg.CountryBytesLimitPercent,
|
||||
country,
|
||||
"SWW_WAF_COUNTRY_BYTES_LIMIT_PERCENT",
|
||||
config.CountryBytesLimitPercentSetting,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"sneak.berlin/go/smallwebwaf/internal/config"
|
||||
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
||||
)
|
||||
|
||||
@@ -33,7 +34,8 @@ func (countries) check(
|
||||
return &verdict{
|
||||
action: requestlog.ActionCountryDenied,
|
||||
figures: map[string]any{
|
||||
"country": country, "setting": "SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES",
|
||||
"country": country,
|
||||
"setting": config.ExclusivelyAllowedCountriesSetting,
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user