Skip to main content

Custom rules

Custom rules let you decide about traffic using your knowledge of the application, without depending on the generic OWASP rules. There is no script, no expression and no regular expression: each rule is a condition picked from a list and an action.

Custom rules​

A rule has three parts:

PartWhat it defines
ConditionWhat the request must have to match
ActionWhat the WAF does when the condition matches
PriorityThe evaluation order among your rules

A single rule can combine more than one condition. The rule only matches when all conditions hold at the same time.

Conditions​

ConditionHow it worksExample
IPCompares the client address with an address203.0.113.10
CIDRCompares the client address with a range, IPv4 or IPv6203.0.113.0/24
COUNTRYCompares the client country; accepts several countriesBR, US
URL_PATHCompares the path, exact or by prefix/admin as a prefix
HTTP_METHODCompares the request methodPOST
HTTP_HEADERCompares a header, by equality, contains or prefixX-Api-Version contains 2.
USER_AGENTCompares the client agent, by equality, contains or prefixcurl as contains

The country comes from the DB-IP Lite database, updated monthly. The required attribution is: IP geolocation by DB-IP, CC BY 4.0 license. Geolocation is an approximation — do not use country as the only access control for sensitive data.

Some headers cannot be used as a condition, because the WAF needs them to route and deliver the request: Authorization, Cookie, Host and the X-Forwarded-* family. To handle authorization or session data, use the OWASP rule set plus a narrow exception, not a custom rule.

Actions​

ActionReturned codeWhat happens
BLOCK403The request is refused and logged as an event
ALLOW—Evaluation of the following custom rules stops for that request
MONITOR—The request passes and the case is logged as an event
RATE_LIMIT429The request counts against the limit set in the rule

ALLOW is the most confusing point: it stops only the following custom rules. OWASP inspection and rate limiting still apply to that request.

RATE_LIMIT on a rule limits a specific path, on top of the domain-wide limit. Excess requests get 429 and appear in the events. See Rate limiting.

Evaluation order​

platform controls → rate limiting → custom rules (by priority) → OWASP rule set
  1. Platform controls — the NNumbers baseline, the same for everyone.
  2. Rate limiting — the domain limit and the per-path limits.
  3. Custom rules — in priority order: the lower number is evaluated first.
  4. OWASP rule set — the anomaly evaluation that decides blocking in prevention.

If two of your rules match the same request, the lower number decides. That is why allow rules need a low number when they must win over block rules.

Examples​

GoalConditionActionPriority
Block admin panel access from outside BrazilURL_PATH prefix /admin and COUNTRY not BRBLOCK10
Allow a partner using a legacy integration on /api/legacyIP equal to the partner address and URL_PATH prefix /api/legacyALLOW20
Observe PUT attempts on the API before blockingHTTP_METHOD PUT and URL_PATH prefix /apiMONITOR30
Limit bulk downloadURL_PATH prefix /exportRATE_LIMIT40
Block known scanning agentsUSER_AGENT contains masscanBLOCK50
The wrong action is not fixed by the OWASP rule set

If an ALLOW lets through something that should be blocked, the fix is in the rule priority or condition — not in the paranoia level.

Next steps​