CasWAF
Rules

Rules

Rules decide what happens to a request before it is forwarded. A rule is defined once in the rule list and can be attached to any number of sites.

Rule types

TypeMatches onPage
IPThe client address, a list of addresses and ranges, or traffic from abroadIP rules
User-AgentThe User-Agent headerUser-Agent and URL path
URL PathThe path, without the query stringUser-Agent and URL path
IP Rate LimitingRequests per second from one addressRate limiting
WAFModSecurity SecLang rules, run by CorazaWAF rules
CompoundOther rules, combined with and and orBelow

A rule holds one or more Expressions. For IP, User-Agent and URL Path, the rule matches when any of its expressions matches; to require several conditions at once, use a compound rule.

Actions

ActionWhat happensDefault status
BlockCasWAF answers itself with Blocked by CasWAF: <reason>403
AllowThe request is forwarded, and the site's remaining rules are skipped200
CAPTCHAThe visitor is sent through a CAPTCHA first; see CAPTCHA302

Status code replaces the default status, for instance 429 for a block, or 404 to hide that anything is there. IP Rate Limiting rules always block, and WAF rules take their action from the SecLang rule that matched.

The reason

For a block, the visitor reads a reason:

  • Reason of the rule, when set, such as Your request is blocked.
  • otherwise hit rule <owner>/<name>: <what matched>.

With Verbose mode on, the reason also names the rule and the expression that matched, which helps while writing rules. To keep all of that from visitors on one site, turn on Disable verbose on the site: its blocked visitors then read only "the rule has been hit".

Attaching rules to a site

Open the site and pick the rules under Rules. They are checked in the order listed, after the redirects and login protection, and the first rule that matches decides. When none matches, the request is forwarded.

Order them from the most specific to the most general. A common setup:

  1. An IP rule with action Allow for your office and monitoring addresses, so nothing after it can lock them out.
  2. A User-Agent rule that blocks known bad crawlers.
  3. An IP Rate Limiting rule.
  4. WAF rules.

Changes to rules and to a site's list take effect within a few seconds. Add and save a rule before attaching it, and detach it from every site before deleting it: a site that lists a rule which does not exist answers every request with an error.

Compound rules

A Compound rule matches when a combination of other rules matches, and then applies its own action. Each expression names one rule, as <owner>/<name>, with a Logic of begin for the first, then and or or. The rules it names only count as matching or not; their own actions are ignored.

and binds tighter than or, so A and B or C and D means (A and B) or (C and D). For example, to send visitors from abroad who open the login page through a CAPTCHA:

  1. An IP rule admin/abroad, operator is abroad.
  2. A URL Path rule admin/login-page, operator match, value ^/login.
  3. A Compound rule with begin admin/abroad and and admin/login-page, action CAPTCHA. Attach only this one to the site.

A compound rule can name other compound rules, up to eight levels deep. One that ends up naming itself answers with an error instead of looping.

Edit on GitHub

On this page