SEAKSES · 30+ Global DNS Resolvers, SSL/PKI Suite & Open REST APISpotted a bug or have an idea?

Upgraded to ModSecurity 3 but Old Rules Stopped Blocking? Check the Directive Changes

By Candra Octavian Ramadhani·2026-11-28T17:49:51+08:00·7 min read
Key Takeaway

After migrating from ModSecurity 2 to 3, some WAF rules silently stop working because deprecated directives and changed phase-handling behave differently. The reader will know which directives broke, how to audit active rules with modsec-rules-check, and what to rewrite to restore blocking behavior.

You moved a server from ModSecurity 2 to ModSecurity 3, the web server started cleanly, and the WAF looks enabled. Then a request that used to get a 403 goes straight through to the application. No error appears in the logs, and the rules file is clearly there. Usually the rules are still present but no longer do what they did before. The engine changed underneath them, and some directives, actions and phase behaviors did not carry over.

This shows up often in support when a customer reports that their old custom rules stopped protecting a login page or an upload form after a stack upgrade. Checking whether the rule exists tells you very little. To find the cause, you need to see how v3 processes a request differently from v2.

How v2 and v3 handle a request differently

ModSecurity 2 (mod_security2) is an Apache module. It hooks directly into Apache's request lifecycle, so Apache itself decides when each phase runs. Phase 1 runs when request headers arrive, phase 2 after the request body is read, phase 3 on response headers, phase 4 on the response body, and phase 5 at logging time. When a rule fires deny, the module tells Apache to stop and return the status code, and Apache does it.

ModSecurity 3 (libmodsecurity) is a standalone C++ library that knows nothing about Apache or Nginx. A separate piece of code called a connector (ModSecurity-nginx or ModSecurity-apache) feeds request data into the library and asks for a decision. For each request, the connector creates a transaction and calls the library step by step:

  1. msc_process_connection() with client and server IP and port.
  2. msc_process_uri() with the URI, method and HTTP version.
  3. msc_add_request_header() for each header, then msc_process_request_headers(), which runs phase 1.
  4. msc_append_request_body() with body chunks, then msc_process_request_body(), which runs phase 2.
  5. The same pattern for response headers (phase 3) and the response body (phase 4).
  6. msc_process_logging(), which runs phase 5.

After each step, the connector calls msc_intervention() to ask whether a rule requested a block, a redirect or a status change. The library does not block anything itself. It records that an intervention is pending, and the connector has to act on it.

That design explains most of the surprises after an upgrade. A rule can match and log correctly while the connector is no longer in a position to change the response. On the response side, the web server may already have sent headers to the client by the time phase 3 or phase 4 finishes. A deny at that point can end up as a log entry only, or as a truncated response, depending on the connector and how it buffers. Rules that relied on phase 4 blocking in Apache with v2 are the most likely to lose their effect.

The directives and actions that changed

The ModSecurity migration documentation notes that some SecLang directives, variable initializations and collection timeouts behave differently or are unsupported in v3. In practice, these are the areas to check:

AreaWhat happens under v3What to do
Engine-level directives such as SecGuardianLog, SecChrootDir, SecDisableBackendCompression, SecContentInjectionNot implemented in libmodsecurity, so the feature is goneRemove them. Do the same job in the web server or OS if you still need it
SecRequestBodyInMemoryLimit and stream inspection directivesListed as unsupported in v3 docsRely on SecRequestBodyLimit and the connector or web server body limits
append / prepend actionsContent injection is not availableDrop rules that depend on it
Persistent collections (initcol, setsid, setuid)Persistence depends on how the library was built (LMDB is optional)Confirm the build, or move rate limiting to the web server
expirevarHas had known gaps in v3Test any counter that relies on expiry

Persistent collections are the case that most often looks like silent failure. A typical v2 brute-force rule increments ip.login_attempts on every failed login and blocks once the counter passes a threshold. If the v3 build keeps collections only in memory per worker, or never writes them anywhere, the counter never reaches the threshold. The rule parses, it matches every request, and it still never blocks.

The other common cause is the config file itself. The Nevis guide on upgrading CRS recommends comparing your old modsecurity.conf with the modsecurity.conf-recommended shipped with the new version. The new file includes settings such as SecPcreMatchLimit and request body controls. It also ships with SecRuleEngine DetectionOnly, which logs matches and never blocks. If someone copied the recommended file in place and never changed that line, nothing blocks at all.

Lint the rules with modsec-rules-check

libmodsecurity ships a small tool called modsec-rules-check. It loads a rules file with the same parser the engine uses and reports anything it cannot handle. Whether your distribution package includes it varies. If it is missing, it is built from the tools/rules-check directory of the libmodsecurity source tree.

Run it against the main config and against each custom rules file separately, so an error points to a specific file:

modsec-rules-check /etc/modsecurity/modsecurity.conf
modsec-rules-check /etc/modsecurity/custom/login-protect.conf

# Illustrative output format (wording differs by version):
# : /etc/modsecurity/modsecurity.conf  --  Loaded 0 rules.
# Test ok.
# : /etc/modsecurity/custom/login-protect.conf  --
# Problems loading the rules: ... unsupported directive or action ...

A parse error is the easy case, because it tells you exactly which line to fix. A clean result does not prove the rules block anything. Directives involving collections and expiry usually parse fine and still fail at runtime, so search for them directly. Adjust the path to wherever your rules live:

grep -rnE 'initcol|setsid|setuid|expirevar|append:|prepend:|phase:(3|4)|SecRuleEngine|SecDefaultAction' /etc/modsecurity/

The hits form your review list. Lines with phase:3 or phase:4 combined with deny need a check of how your connector handles response-side blocking. Lines with collections need confirmation that the build persists them. SecRuleEngine shows you whether detection-only mode is set anywhere, including in per-site overrides.

Also check SecDefaultAction. In older setups, many rules had no disruptive action of their own and inherited deny from a SecDefaultAction line in the old config. If the new config sets a different default, or the line now carries a different phase, those rules start logging matches without blocking.

Prove blocking end to end with a canary rule

The library and the connector are separate pieces, so test both at once with a rule that has to block. Add a harmless canary rule that only fires on a query parameter nobody uses:

# Canary rule: blocks only requests carrying ?modsec_canary=1
SecRule ARGS_GET:modsec_canary '@streq 1' 'id:1009001,phase:1,deny,status:403,log,msg:'"'"'Canary rule hit'"'"''

# Then, from a shell (reload the web server first):
# curl -s -o /dev/null -w '%{http_code}
' 'https://example.com/?modsec_canary=1'
# Expected: 403. A 200 means the connector is not enforcing interventions.

If you want to avoid the nested quoting, write the msg with double quotes in the rules file, which is the usual SecLang style. The single-quote form above exists only to survive copying through shell snippets.

A 200 on the canary points to something more basic than individual rules. On Nginx, check that modsecurity on; is set in the right server or location block, and that modsecurity_rules_file points to the file that includes your rules. On Apache with the v3 connector, check that the old mod_security2 module is not still loaded alongside it, competing for the same config. When the canary returns 403, move the same deny to phase 2, test with a POST body, and then test any response-side rules you depend on. Remove the canary when you finish.

Rewriting what no longer works

Most fixes are small. Move blocking decisions to phase 1 or phase 2 wherever possible. The connector can always stop a request before it reaches the backend, and you avoid the question of whether response headers have already been sent. Response-side rules (data leakage, error page detection) are often better kept as detection rules that log, with blocking handled earlier.

For rate limiting and brute-force counters, decide whether ModSecurity is the right layer. If your build has working persistent storage and you have tested it under load with several workers, the collection-based rules can stay. If not, the web server's own rate limiting, or a log-based tool such as fail2ban, is usually more predictable. Collection-based limits often fail quietly in exactly this way.

The rule set matters as well. A discussion on Security Stack Exchange about Core Rule Set 4 points out that upgrading the engine while keeping an old rule set can cause warnings or broken behavior. CRS versions also renamed variables between releases, so a custom rule that checks an old anomaly score name reads a variable nothing sets anymore. Keep your own exclusions and custom rules in a separate file, as the ProSec article on custom rules suggests with a dedicated RESPONSE-999-EXCLUSION-RULES.conf. That way, a rule set update does not overwrite them, and you can review them as one unit after each upgrade.

After any ModSecurity 3 upgrade, run three checks before you trust the WAF. Run modsec-rules-check on every rules file. Grep for collections, response-phase denies and the engine mode. Confirm with a canary request that a phase 1 deny actually returns 403. A clean config test and a running web server only show that the rules loaded.