The error message:
Expecting an action, got: SecRule &REQUEST_HEADERS:Referer "@eq 0"
means ModSecurity is expecting rule actions (like phase:2, id:xxx, chain, deny, msg, etc.) after a SecRule directive, but in your chained rules you only gave a condition without a second quoted string for actions.
Why is this happening?
Each SecRule directive requires two arguments:
-
The variable(s) and operator/values (the "condition") — e.g. &REQUEST_HEADERS:Referer "@eq 0"
-
The actions string, enclosed in double quotes — e.g. "chain"
So a minimal chained rule looks like:
SecRule &REQUEST_HEADERS:Referer "@eq 0" "chain"
Without the second argument (the action string), ModSecurity will throw the error you saw.
Your problematic section is:
SecRule REQUEST_METHOD "!^(GET|HEAD|OPTIONS)$" "phase:2,id:240004,deny,status:403,msg:'no referer or origin',chain"
SecRule &REQUEST_HEADERS:Origin "@eq 0" "chain"
SecRule &REQUEST_HEADERS:Referer "@eq 0"
Notice the last chained rule:
SecRule &REQUEST_HEADERS:Referer "@eq 0"
Missing the 2nd argument (action string)!
How to fix it?
Add "chain" as an action to the second chained rule as well because it is still part of the chain:
SecRule REQUEST_METHOD "!^(GET|HEAD|OPTIONS)$" "phase:2,id:240004,deny,status:403,msg:'no referer or origin',chain"
SecRule &REQUEST_HEADERS:Origin "@eq 0" "chain"
SecRule &REQUEST_HEADERS:Referer "@eq 0"
But wait, this will cause another error because the last rule in a chain must not have chain keyword.
The chain is a linear sequence of rules where all but the last end with chain.
So the last one in chain has no chain keyword.
Thus the fix is:
SecRule REQUEST_METHOD "!^(GET|HEAD|OPTIONS)$" "phase:2,id:240004,deny,status:403,msg:'no referer or origin',chain"
SecRule &REQUEST_HEADERS:Origin "@eq 0" "chain"
SecRule &REQUEST_HEADERS:Referer "@eq 0" ""
But an empty string as actions "" is not valid (actions are required).
Correct approach for last chained rule
For the last chained rule, provide an empty action string: just ""
So:
SecRule REQUEST_METHOD "!^(GET|HEAD|OPTIONS)$" "phase:2,id:240004,deny,status:403,msg:'no referer or origin',chain"
SecRule &REQUEST_HEADERS:Origin "@eq 0" "chain"
SecRule &REQUEST_HEADERS:Referer "@eq 0" ""
This tells ModSecurity: no rule actions on this last chained condition, no disrupt, no log, just a condition.
Summary for chained rules:
- First rule (chain starter): disruptive action +
chain
- Intermediate chained rules:
chain only
- Last chained rule: empty actions string
""
Final corrected complete set:
SecAction "id:240001,phase:1,nolog,pass,t:none,setvar:tx.allowed_domain=dmzfw.local"
SecRule REQUEST_METHOD "!^(GET|HEAD|OPTIONS)$" "phase:2,id:240002,deny,status:403,msg:'bad referer',chain"
SecRule &REQUEST_HEADERS:Referer "@gt 0" "chain"
SecRule REQUEST_HEADERS:Referer "!@beginsWith %{tx.allowed_domain}" ""
SecRule REQUEST_METHOD "!^(GET|HEAD|OPTIONS)$" "phase:2,id:240003,deny,status:403,msg:'bad origin',chain"
SecRule &REQUEST_HEADERS:Origin "@gt 0" "chain"
SecRule REQUEST_HEADERS:Origin "!@beginsWith %{tx.allowed_domain}" ""
SecRule REQUEST_METHOD "!^(GET|HEAD|OPTIONS)$" "phase:2,id:240004,deny,status:403,msg:'no referer or origin',chain"
SecRule &REQUEST_HEADERS:Origin "@eq 0" "chain"
SecRule &REQUEST_HEADERS:Referer "@eq 0" ""
Extra tip:
- The last chained rule must always have an action string, even if empty (
"").
- When in doubt, put
"" for the last chained rule.
If you do this, the error Expecting an action will go away and your rules will work as intended.