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
| Type | Matches on | Page |
|---|---|---|
IP | The client address, a list of addresses and ranges, or traffic from abroad | IP rules |
User-Agent | The User-Agent header | User-Agent and URL path |
URL Path | The path, without the query string | User-Agent and URL path |
IP Rate Limiting | Requests per second from one address | Rate limiting |
WAF | ModSecurity SecLang rules, run by Coraza | WAF rules |
Compound | Other rules, combined with and and or | Below |
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
| Action | What happens | Default status |
|---|---|---|
Block | CasWAF answers itself with Blocked by CasWAF: <reason> | 403 |
Allow | The request is forwarded, and the site's remaining rules are skipped | 200 |
CAPTCHA | The visitor is sent through a CAPTCHA first; see CAPTCHA | 302 |
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:
- An
IPrule with actionAllowfor your office and monitoring addresses, so nothing after it can lock them out. - A
User-Agentrule that blocks known bad crawlers. - An
IP Rate Limitingrule. WAFrules.
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:
- An
IPruleadmin/abroad, operatoris abroad. - A
URL Pathruleadmin/login-page, operatormatch, value^/login. - A
Compoundrule withbegin admin/abroadandand admin/login-page, actionCAPTCHA. 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.