check / check (push) Failing after 1m42s
Every heuristic is a struct built once in newHandler with the settings and collaborators it reads; no check reads the handler. The six lists are handler fields built there. Code several heuristics share takes what it needs as arguments or lives on a struct they hold: banMaker for bans and their alerts, reputationHitNoter for reputation hits, biasedThresholds for limit percentages. The handler keeps blocklists, rateLimits, trapPaths, ruleFiles and coreRuleSet as fields too, since refusedWhateverTheAnswer and findBesideLookup use them. Model: opus-5-5
37 lines
685 B
Go
37 lines
685 B
Go
package waf
|
|
|
|
// The heuristic tag_deny. It reads SWW_WAF_TAG_DENY.
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"time"
|
|
|
|
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
|
)
|
|
|
|
// tagDeny refuses a request that carries a tag in SWW_WAF_TAG_DENY. Its figure is
|
|
// the first such tag, in sorted order.
|
|
type tagDeny struct {
|
|
tags []string // SWW_WAF_TAG_DENY
|
|
}
|
|
|
|
func (tagDeny) name() string { return "tag_deny" }
|
|
|
|
func (t tagDeny) check(
|
|
_ context.Context,
|
|
rq *request,
|
|
_ time.Time,
|
|
) *verdict {
|
|
for _, tag := range rq.line.Tags {
|
|
if slices.Contains(t.tags, tag) {
|
|
return &verdict{
|
|
action: requestlog.ActionClientDenied,
|
|
figures: map[string]any{"tag": tag},
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|