check / check (push) Successful in 3m54s
go.uber.org/fx builds the parts of waf and rproxy in internal/sww, one provider per part. Each background loop is a lifecycle hook added where its part is built. waf.Params takes every part built, and waf.New builds none. GeoJS calls back into waf, so waf exports AddLookup and GeoJSFailed, and clientGroup and banNetblock take the settings. newServer, loadStateFiles, the inBackground list and serveRProxy are gone. serve is the one hook that serves both daemons, and reports a failure to run on a channel of its own; fx's signal handling is not used. Once fx has stopped, run takes each daemon's last step: waf writes the state files, and rproxy waits for its reports. Model: opus-5-5
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package waf
|
|
|
|
// What the reputation heuristics share: blocklists, dnsbl and abuseipdb.
|
|
|
|
import (
|
|
"sneak.berlin/go/smallwebwaf/internal/alerts"
|
|
"sneak.berlin/go/smallwebwaf/internal/bans"
|
|
)
|
|
|
|
// deny is the SWW_WAF_BLOCKLIST_ACTION and the SWW_WAF_DNSBL_ABUSEIPDB_ACTION that
|
|
// refuses the requests of a client a source lists.
|
|
const deny = "deny"
|
|
|
|
// noteListed notes each of sources, the URLs of the blocklists or the
|
|
// DNSBL zones, their keys masked, that list the client, as noteHit does,
|
|
// with reason.
|
|
func (rq *request) noteListed(sources []string, reason string) {
|
|
for _, source := range sources {
|
|
rq.noteHit(bans.ReputationHit{Source: source}, reason)
|
|
}
|
|
}
|
|
|
|
// noteHit adds hit's source, which lists the client, to the log line's
|
|
// reputation, and hit to the notes of a ban the request makes, counts the
|
|
// source in the metrics, and raises a reputation_hit alert with reason,
|
|
// whose detail gives hit's source and score.
|
|
func (rq *request) noteHit(hit bans.ReputationHit, reason string) {
|
|
detail := map[string]any{"source": hit.Source}
|
|
if hit.Score != nil {
|
|
detail["score"] = *hit.Score
|
|
}
|
|
|
|
rq.line.Reputation = append(rq.line.Reputation, hit.Source)
|
|
rq.reputation = append(rq.reputation, hit)
|
|
rq.h.metrics.ReputationHit(hit.Source)
|
|
rq.h.alerts.Raise(alerts.Alert{
|
|
Event: alerts.EventReputationHit,
|
|
Host: rq.site,
|
|
Client: rq.client,
|
|
Netblock: clientGroup(rq.h.config, rq.client),
|
|
ASN: rq.line.ASN,
|
|
ASName: rq.line.ASName,
|
|
Country: rq.line.Country,
|
|
Reason: reason,
|
|
Detail: detail,
|
|
})
|
|
}
|