Documentation
¶
Overview ¶
Package rules defines the interface between the inspection pipeline and a rule engine. Coraza is the first implementation (package rules/coraza); the interface keeps a different engine possible without touching adapters.
Evaluation takes a whole request with its buffered body prefix. Every adapter gathers the body before deciding, the ext_proc adapter too (Envoy's BUFFERED_PARTIAL body, or the chunks it streams in observability mode). Streaming evaluation (headers, then body chunks) is not built.
An ExchangeEvaluator also keeps a request's evaluation open for its response (phases 3 and 4), for the policies that inspect responses: the response rules see what the request rules set (the paranoia level, the anomaly scores, the user's variables).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ResponseBodyTypes = []string{
"text/plain", "text/html", "text/xml", "text/csv",
"text/javascript", "application/javascript", "application/x-javascript", "application/ecmascript",
"application/json", "application/xml", "application/problem+json", "application/xhtml+xml",
}
ResponseBodyTypes are the media types of the response bodies the rules read, besides those ResponseBodyType reads as one of them; adapters buffer no others. A user's SecResponseBodyMimeType changes what Coraza reads, not what adapters buffer.
Functions ¶
func ResponseBodyType ¶ added in v0.4.3
ResponseBodyType is the media type of ResponseBodyTypes the rules read a response body with this Content-Type as, or "" for a body they don't read. The media type is what comes before the first ";", trimmed and lowercased, so a parameter a strict parser rejects ("text/html; charset") doesn't hide the type a browser renders. A type with a structured syntax suffix reads as its suffix's (application/vnd.api+json as application/json, image/svg+xml as application/xml), but for gRPC's and Connect's streams. No type, or one that isn't type/subtype, may be anything a browser sniffs: it reads as text/plain. Several values (a header sent twice, joined with ",") aren't one type, so they read as text/plain too.
Types ¶
type DetectingEvaluator ¶ added in v0.5.0
type DetectingEvaluator interface {
ExchangeEvaluator
// EvaluateExchangeDetecting evaluates r without interrupting it: Result
// reports what would have interrupted it (Interrupted, RuleID), and the
// evaluation is kept for the response even then, since the response
// reaches the client. The caller must Close the Exchange.
EvaluateExchangeDetecting(ctx context.Context, r *request.Request) (Result, Exchange, error)
}
DetectingEvaluator evaluates for a policy in Detect mode, whose requests are never denied (#360).
type Evaluator ¶
Evaluator evaluates requests against a compiled rule set. Implementations must be safe for concurrent use.
type Exchange ¶ added in v0.4.0
type Exchange interface {
// EvaluateResponse evaluates the response (phases 3 and 4), once. The
// result lists only what matched the response.
EvaluateResponse(ctx context.Context, resp *request.Response) (Result, error)
// Close releases the evaluation.
Close()
}
Exchange is a request's evaluation, kept for its response. It is not safe for concurrent use.
type ExchangeEvaluator ¶ added in v0.4.0
type ExchangeEvaluator interface {
Evaluator
// EvaluateExchange evaluates r as Evaluate does and, unless the
// request was interrupted, returns the evaluation to continue with the
// response. The caller must Close it.
EvaluateExchange(ctx context.Context, r *request.Request) (Result, Exchange, error)
}
ExchangeEvaluator is an Evaluator that can keep a request's evaluation open for its response.
type Match ¶ added in v0.1.1
type Match struct {
RuleID int
// Variable is the collection and key, e.g. ARGS:id.
Variable string
// Value is the matched data.
Value string
}
Match is where a rule matched.
type Result ¶
type Result struct {
// Interrupted reports that a rule asked to block the request.
Interrupted bool
// Status is the HTTP status the blocking rule asked for (0 if unset).
Status int
// RuleID is the rule that interrupted the request, if any.
RuleID int
// MatchedRuleIDs lists every rule that matched request data, including
// rules that only contributed to an anomaly score.
MatchedRuleIDs []int
// Matches says where each of those rules matched, unredacted: the
// caller redacts before anything leaves the engine.
Matches []Match
// AnomalyScore is the CRS inbound anomaly score (0 without CRS), or
// the outbound one for a response.
AnomalyScore int
// Detected reports that rules above the CRS's blocking paranoia level,
// up to its detection level, reached the anomaly threshold: the request
// (or response) is logged, never blocked, for them.
Detected bool
}
Result is the outcome of evaluating one request.
type Swap ¶ added in v0.5.0
type Swap struct {
// contains filtered or unexported fields
}
Swap is an Evaluator whose rules can be replaced while it serves (standalone mode's rule reload, #359): an evaluation runs entirely on the evaluator it started with, and those that start after Store use the new one. It is safe for concurrent use.
func (*Swap) EvaluateExchange ¶ added in v0.5.0
EvaluateExchange implements ExchangeEvaluator: with the current evaluator's exchange, or none if it keeps none.