How to make AND statement in ModSecurity rules
- User
How to make AND statement in ModSecurity rules
- Assistant
In ModSecurity, to create an AND condition in rules, you generally combine multiple
SecRuledirectives with thechainaction. The chained rules act as an AND because every condition in the chain must be true for the whole rule set to trigger.How does
chainwork?- The first
SecRuleis evaluated. - If true, the next
SecRulein the chain is evaluated. - This continues until all chained rules are evaluated.
- If any rule in the chain fails, the entire chain fails.
- If all succeed, the action is triggered.
Example of AND with
chainapache - The first
- User
SecRule REQUEST_URI "^/DVWA/security.php$" "id:240004,phase:2,nolog,pass,chain" SecRule REQUEST_HEADERS:Referer "!@contains %{tx.allowed_domain}"
"deny,status:403,log,msg:'bad referer'"SecRule REQUEST_URI "^/DVWA/security.php$" "id:240005,phase:2,nolog,pass,chain" SecRule REQUEST_HEADERS:Origin "!@contains %{tx.allowed_domain}"
"deny,status:403,log,msg:'bad origin'"Check these rules for errors and mistakes. nginx -t shows: [emerg] 922#922: "modsecurity_rules_file" directive Disruptive actions can only be specified by chain starter rules. in /etc/nginx/sites-enabled/website-proxy.conf:7
- Assistant
The error message: