Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶
func Middleware(waf coraza.WAF) fox.MiddlewareFunc
Middleware creates a new Fox middleware function using the provided Coraza WAF instance. It intercepts incoming requests and processes them through coraza.WAF before passing them to the next handler.
func WithTransactionHook ¶ added in v0.36.0
func WithTransactionHook(hooks ...Hook) fox.RouteOption
WithTransactionHook attaches hooks to a route. For every request matching the route, the middleware calls the hooks in the given order, once the connection, URI and request headers are populated in the transaction and right before the request headers phase (phase 1) is evaluated. Hooks are not called when the rule engine is off. Applying this option more than once to the same route replaces the previously attached hooks. It panics if a hook is nil.
Types ¶
type Context ¶ added in v0.36.0
type Context interface {
Request() *http.Request
RemoteIP() netip.Addr
ClientIP() (netip.Addr, error)
Method() string
RoutingPath() string
Host() string
QueryParams() url.Values
QueryParam(name string) string
Header(key string) string
Route() *fox.Route
Param(name string) string
Params() iter.Seq[fox.Param]
// contains filtered or unexported methods
}
Context is the subset of the fox.Context API passed to a Hook, without access to the response.
type Hook ¶ added in v0.36.0
type Hook func(c Context, tx types.Transaction)
Hook customizes a transaction before Coraza evaluates any rule. It must not retain c or tx.
func RemoveRuleRange ¶ added in v0.36.0
RemoveRuleRange returns a Hook that removes the rules whose ID is between start and end inclusive from the transaction, the per-route equivalent of ctl:ruleRemoveById with a range. The rules of the WAF are not affected. Removing rules requires a transaction created by the Coraza WAF implementation. For any other transaction, the hook is a no-op. It panics if start is greater than end.
func RemoveRules ¶ added in v0.36.0
RemoveRules returns a Hook that removes the rules with the given IDs from the transaction, the per-route equivalent of ctl:ruleRemoveById. The rules of the WAF are not affected. Removing rules requires a transaction created by the Coraza WAF implementation. For any other transaction, the hook is a no-op.
func TxVar ¶ added in v0.36.0
TxVar returns a Hook that sets the transaction variable TX:key to value, overwriting any previous value. Since rules read TX variables at evaluation time, this is the way to configure per-route behaviors that rule sets expose through TX variables, such as enabling an OWASP CRS plugin or setting the paranoia level. Setting TX variables requires a transaction that implements plugintypes.TransactionState, as the transactions of the Coraza WAF implementation do. For any other transaction, the hook is a no-op.