Please rewrite this ModSecurity rules to return 200 http code with blank page
Assistant
To modify the ModSecurity rules so that instead of blocking with the default block action (which usually returns 403 Forbidden), they return HTTP 200 with a blank page, you need to do two things:
Instead of using block action, use allow plus ctl:ruleEngine=Off for the phase, or use deny with status:200 and a custom disruptive action.
To send a blank response and HTTP 200, you can use deny with status:200 and create an empty response body.
Unfortunately, ModSecurity doesn't directly provide an easy deny with status 200 return and blank page in one simple action. But you can work around by using deny with status:200 and use skip or return and empty response body.
One approach is:
In the rule, change block to deny,status:200,log plus skip or ctl:inboundAnomalyScore=+100 to fully deny the request but respond with 200.
Use SecDefaultAction or SecResponseBodyAccess and SecResponseBodyMimeType rules to send an empty response.
Another approach:
Use deny,status:200,log and a separate SecRule triggered on phase:3 or 4 that manipulates the response body to blank.
Simplified approach:
Change rules to:
replace block with deny,status:200,log
add ctl:forceRequestBodyVariable=off to avoid side effects
add skipAfter or chain actions if needed.
Also, to return a blank response body, you can set SecResponseBody phase 4 rules to deny,status:200 and inject an empty body, or use ctl:responseBody=off etc.
Here is the rewritten rules reflecting the exact request: "return 200 with a blank page".
apache
# Block access to sensitive file types by URI or args (e.g., README.md)
SecRule REQUEST_URI|ARGS_NAMES|ARGS "@rx (?i)\.(md|txt|bak|config|ini|log|sql|env)$" \
"id:400001,\
phase:1,\
deny,status:200,\
t:none,\
msg:'Returned 200 with blank page for sensitive file extension access',\
severity:'CRITICAL',\
logdata:'Matched Data: %{MATCHED_VAR}',\
tag:'application-multi',\
tag:'file-access',\
tag:'sensitive-file'"
# Block requests specifically to files known to hold sensitive info (customize the list freely)
SecRule REQUEST_URI "@rx (?i)(README(\.md)?|config\.ini|\.env|passwords?.txt|secret\.bak)$" \
"id:400002,\
phase:1,\
deny,status:200,\
t:none,\
msg:'Returned 200 with blank page for known sensitive filename access',\
severity:'CRITICAL',\
logdata:'Matched Data: %{MATCHED_VAR}',\
tag:'application-multi',\
tag:'file-access',\
tag:'sensitive-file'"
# Check response body for sensitive error/sensitive info strings and return 200 with blank page
SecRule RESPONSE_BODY "@rx (?i)(mysql|password|passwd|can't connect|error|exception|trace|fatal|undefined|denied|unauthorized)" \
"id:400003,\
phase:4,\
deny,status:200,\
t:none,\
msg:'Returned 200 with blank page for response containing sensitive info/error disclosure',\
severity:'CRITICAL',\
logdata:'Matched Data: %{MATCHED_VAR}',\
ctl:auditLogParts=+E,\
tag:'application-multi',\
tag:'error-disclosure',\
tag:'sensitive-info',\
tag:'security-misconfiguration'"
Note:
Using deny,status:200 typically stops request processing and returns HTTP 200 to clients.
By default, the body may still contain the original content from the backend server unless ModSecurity is configured to alter the body.
Unfortunately, ModSecurity has limited native ability to modify the response body to empty/blank. To guarantee a blank page, you might need to combine with other webserver features (like error page configuration) or use ctl:responseBodyAccess=Off and ctl:ruleRemoveTargetById in more advanced setups.
Another approach is to use SecAction or Apache/nginx configuration to serve empty responses for these conditions.
If you want a pure ModSecurity-only solution to replace the body with blank, it requires more advanced manipulation: