Give ban causes, limit kinds, alert events, actions and dispositions named types (closes #428)
check / check (push) Waiting to run
check / check (push) Waiting to run
Each fixed set of string constants becomes a named string type in the package that owns it, and the fields and parameters that carry it use the type: bans.Cause, ratelimit.LimitKind, alerts.Event, alerts.DestinationName, rules.Action, requestlog.Action, requestlog.Offence, requestlog.WAFLineKind and waf.Disposition. Every value keeps its string, so the logs, state files, alerts and metrics do not change. The switches exhaustive now checks list their missing cases. Model: opus-5-5
This commit is contained in:
1 parent
433d5cc0a9
commit
93697c452f
41 files changed
+358
-248
No files matched your search
@@ -67,7 +67,7 @@ type request struct {
|
||||
// disposition is what is done with the request: waf's valid disposition,
|
||||
// or SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION. It is "" when neither
|
||||
// gave one.
|
||||
disposition string
|
||||
disposition waf.Disposition
|
||||
// answered is true when waf gave disposition, which makes a report due,
|
||||
// and wafNoAnswer when SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION did.
|
||||
answered bool
|
||||
@@ -454,7 +454,7 @@ func (rq *request) finish(ctx context.Context) {
|
||||
requestEnd.Sub(rq.start),
|
||||
),
|
||||
DurationResponseMS: requestlog.Milliseconds(end.Sub(requestEnd)),
|
||||
Disposition: rq.disposition,
|
||||
Disposition: string(rq.disposition),
|
||||
WAFBackendNoAnswer: rq.wafNoAnswer,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -218,7 +218,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// This panic has Go's server close the connection without an answer,
|
||||
// and log nothing; the deferred finish still runs.
|
||||
panic(http.ErrAbortHandler)
|
||||
default: // a deny, an error, or an answer without a valid disposition
|
||||
case waf.DispositionDeny, "": // "" is an error, or no valid disposition
|
||||
rq.answerWith(answer)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,9 +72,9 @@ const (
|
||||
|
||||
// What the stand-in for waf answers.
|
||||
const (
|
||||
dispositionAllow = waf.DispositionAllow
|
||||
dispositionDeny = waf.DispositionDeny
|
||||
dispositionClose = waf.DispositionClose
|
||||
dispositionAllow = string(waf.DispositionAllow)
|
||||
dispositionDeny = string(waf.DispositionDeny)
|
||||
dispositionClose = string(waf.DispositionClose)
|
||||
// deniedBody is the body of a deny.
|
||||
deniedBody = "refused by waf"
|
||||
)
|
||||
|
||||
@@ -40,7 +40,7 @@ type wafAnswer struct {
|
||||
// notes nothing, and no report is due for it: waf holds no decision to report
|
||||
// on.
|
||||
func (rq *request) noteAnswer(answer *wafAnswer) {
|
||||
disposition := answer.header.Get(waf.DispositionHeader)
|
||||
disposition := waf.Disposition(answer.header.Get(waf.DispositionHeader))
|
||||
|
||||
switch disposition {
|
||||
case waf.DispositionAllow, waf.DispositionDeny,
|
||||
@@ -76,7 +76,9 @@ func (rq *request) handleNoUsableAnswer(ctx context.Context, err error) {
|
||||
// https://git.eeqj.de/sneak/smallwebwaf/issues/182.
|
||||
rq.h.processLog.Warn("waf gave no answer", "error", err.Error())
|
||||
|
||||
rq.disposition = rq.h.config.WAFBackendNoAnswerDisposition
|
||||
rq.disposition = waf.Disposition(
|
||||
rq.h.config.WAFBackendNoAnswerDisposition,
|
||||
)
|
||||
rq.wafNoAnswer = true
|
||||
|
||||
if rq.disposition == waf.DispositionAllow {
|
||||
|
||||
Reference in new issue
Block a user