rules

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
var ResponseBodyTypes = []string{
	"text/plain", "text/html", "text/xml",
	"application/json", "application/xml", "application/problem+json",
}

ResponseBodyTypes are the media types of the response bodies the rules read; adapters buffer no others. A user's SecResponseBodyMimeType changes what Coraza reads, not what adapters buffer.

Functions

This section is empty.

Types

type Evaluator

type Evaluator interface {
	Evaluate(ctx context.Context, r *request.Request) (Result, error)
}

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
}

Result is the outcome of evaluating one request.

Directories

Path Synopsis
Package coraza implements rules.Evaluator with OWASP Coraza and the OWASP Core Rule Set (CRS), which is embedded in the binary.
Package coraza implements rules.Evaluator with OWASP Coraza and the OWASP Core Rule Set (CRS), which is embedded in the binary.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL