waf: each heuristic holds its own settings and parts (closes #441)
check / check (push) Failing after 2m18s
check / check (push) Failing after 2m18s
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
这个提交包含在:
1 父节点
433d5cc0a9
当前提交
a46770ed58
27 个文件已更改
+647
-334
没有与搜索条件相匹配的文件
+15
-8
@@ -16,11 +16,14 @@ import (
|
||||
// it bans the client's netblock, or in observe mode raises the alert for the
|
||||
// ban it would have made. The ban's notes give the path as sent, and so does
|
||||
// its figure.
|
||||
type trapPaths struct{}
|
||||
type trapPaths struct {
|
||||
paths []string // SWW_WAF_TRAP_PATHS
|
||||
banMaker banMaker
|
||||
}
|
||||
|
||||
func (trapPaths) name() string { return "trap_paths" }
|
||||
|
||||
func (trapPaths) check(
|
||||
func (t trapPaths) check(
|
||||
_ context.Context,
|
||||
rq *request,
|
||||
now time.Time,
|
||||
@@ -33,18 +36,22 @@ func (trapPaths) check(
|
||||
rq.attack = true
|
||||
|
||||
return &verdict{
|
||||
action: rq.banForAttack(now, bans.Notes{TrapPath: path}),
|
||||
action: t.banMaker.banForAttack(
|
||||
rq,
|
||||
now,
|
||||
bans.Notes{TrapPath: path},
|
||||
),
|
||||
figures: map[string]any{"path": path},
|
||||
}
|
||||
}
|
||||
|
||||
// trapPath returns the request's path as sent, when its path as a path rule
|
||||
// sees it, without the query, as sent or once percent-decoded, is in
|
||||
// trapPath returns rq's path as sent, when its path as a path rule sees it,
|
||||
// without the query, as sent or once percent-decoded, is in
|
||||
// SWW_WAF_TRAP_PATHS, and "" otherwise.
|
||||
func (rq *request) trapPath() string {
|
||||
func (t trapPaths) trapPath(rq *request) string {
|
||||
path := rules.Path(rq.in)
|
||||
if !slices.Contains(rq.h.config.TrapPaths, path) &&
|
||||
!slices.Contains(rq.h.config.TrapPaths, rules.DecodeOnce(path)) {
|
||||
if !slices.Contains(t.paths, path) &&
|
||||
!slices.Contains(t.paths, rules.DecodeOnce(path)) {
|
||||
return ""
|
||||
}
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户