check / check (push) Failing after 1m42s
Each heuristic that refuses a request sets the status on its verdict. check copies it into the refusal, or in observe mode notes it, and no longer works the status out from the action. refusalLimit takes the status from that verdict instead of from a switch over the action. Model: opus-5-5
39 lines
813 B
Go
39 lines
813 B
Go
package waf
|
|
|
|
// The heuristic tag_deny. It reads SWW_WAF_TAG_DENY and SWW_WAF_BAN_RESPONSE.
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"time"
|
|
|
|
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
|
)
|
|
|
|
// tagDeny refuses a request that carries a tag in SWW_WAF_TAG_DENY, with
|
|
// SWW_WAF_BAN_RESPONSE. Its figure is the first such tag, in sorted order.
|
|
type tagDeny struct {
|
|
tags []string // SWW_WAF_TAG_DENY
|
|
banResponse int // SWW_WAF_BAN_RESPONSE
|
|
}
|
|
|
|
func (tagDeny) name() string { return "tag_deny" }
|
|
|
|
func (t tagDeny) check(
|
|
_ context.Context,
|
|
rq *request,
|
|
_ time.Time,
|
|
) *verdict {
|
|
for _, tag := range rq.tags {
|
|
if slices.Contains(t.tags, tag) {
|
|
return &verdict{
|
|
action: requestlog.ActionClientDenied,
|
|
status: t.banResponse,
|
|
figures: map[string]any{"tag": tag},
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|