Repository navigation
fix(modsecurity): avoid ctl:ruleEngine=Off cancelling allow on whitelist rule 9800000 (#4248) - #4258
Mohit20057 wants to merge 1 commit into
Conversation
β¦ist rule 9800000 (bunkerity#4248)
|
No actionable comments were generated in the recent review. Component summary
Security impact
User-visible behaviour
Configuration, schema, packaging
Documentation and tests
WalkthroughThe whitelist rule is split into an ChangesWhitelist bypass
Estimated code review effort: 3 (Moderate) | ~20 minutes Severity of issue fixed: Low Assessment against linked issues
Possibly related issues Merge Risk:
|
There was a problem hiding this comment.
βΉοΈ No critical issues β one scope note on the
DetectionOnlypath.
Approach: sound β splitting the kill switch lets allow run while the engine is On, and the separate ctl:ruleEngine=Off fallback keeps phases 2β5 bypassed in DetectionOnly. The rule order is asserted by the render test.
Reviewed changes
- Per-service kill switch:
9800000now carries onlyallow,nolog; new9800001carriespass,nolog,ctl:ruleEngine=Offfor theDetectionOnlypath, both placed before the CRS include. - Global-CRS kill switch: the same split pair added to the shared http rules file, ahead of the CRS include.
- Unit tests: render the per-service and global templates with
USE_WHITELIST/USE_MODSECURITY_CRS/SECURITY_MODEvariants and assert the rendered rule lines and their relative order. - Integration spec: adds a non-whitelisted baseline (
403+[id "920420"]) and per-service/global whitelisted checks (200+ no920420) usingContent-Type: application/octet-stream.
Verification: I confirmed the ModSecurity v3 premise in upstream source (executeActionsAfterFullMatch runs ctl before the disruptive action, executeAction skips disruptive actions when the engine is not On, and FromNowOnAllowType skips all phases except logging). Rendering both templates through the shipped Configurator/Templator reproduces all five unit-test assertions, and python3 -m py_compile on the new test is clean. No Docker integration run was performed here.
βΉοΈ #4248's phase-1 residue remains in DetectionOnly
In DetectionOnly the disruptive allow does not run, so 9800001 switches the engine off β but that does not stop the rest of phase 1, because RulesSet::evaluate never re-checks the engine state inside a phase. Whitelisted clients still generate 920420-style log entries in detect mode, which is the symptom named in #4248. This is not a regression (the old combined rule behaved the same way), and the PR body accurately scopes the fallback to phases 2β5, but closing #4248 will imply the field no longer sees these lines.
Technical details
# DetectionOnly keeps evaluating the rest of phase 1
## Affected sites
- `src/common/core/modsecurity/confs/server-http/modsecurity-rules.conf.modsec:217`
- `src/common/core/modsecurity/confs/http/modsecurity-rules-global-crs.conf.modsec:167`
- `tests/unit/modsecurity/test_whitelist_bypass_rule.py:82-86` β asserts the rendered fallback text only
## Failure mechanism
- With `SecRuleEngine DetectionOnly`, `RuleWithActions::executeAction` skips the disruptive `allow` on `9800000`
(`src/rule_with_actions.cc`), so `9800001` runs and sets `transaction->m_secRuleEngine = Disabled`
(`src/actions/ctl/rule_engine.cc`).
- `RulesSet::evaluate` checks `m_allowType` and engine state only at phase entry, never between rules in the same
phase (`src/rules_set.cc`). The remaining phase-1 CRS rules therefore still match and call `performLogging`.
- Later phases do early-return on `getRuleEngineState() == Disabled`, so only phases 2β5 are bypassed by the fallback.
## Required outcome
- Either the `DetectionOnly` path also stops the rest of phase 1 for whitelisted clients, or the limitation is stated
where #4248 is closed so "whitelisted clients skip all ModSecurity rules" is not claimed for detect mode.
## Suggested approach (optional)
- Add a `SECURITY_MODE=detect` action to `tests/core/modsecurity.yml` with `USE_WHITELIST=yes` and
`WHITELIST_IP=0.0.0.0/0` asserting `not_log: '[id "920420"]'`, so the `9800001` branch is exercised at runtime
rather than only through rendered text.deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) ο½ π

Summary
In libModSecurity v3 (
RuleWithActions::executeActionsAfterFullMatch), non-disruptive actions (ctl:ruleEngine=Off) execute before disruptive actions (allow), andexecuteActionskips disruptive actions wheneverSecRuleEngineis notOn. Combiningallowwithctl:ruleEngine=Offon rule9800000therefore disabled the engine beforeallowcould run, leaving the remaining phase 1 CRS rules (such as920420) running and logging for whitelisted clients.This PR updates both
src/common/core/modsecurity/confs/server-http/modsecurity-rules.conf.modsecandsrc/common/core/modsecurity/confs/http/modsecurity-rules-global-crs.conf.modsec:id:9800000asphase:1,allow,nologsoallowexecutes inSecRuleEngine Onmode and skips all remaining phase 1 rules as well as phases 2β4.id:9800001(phase:1,pass,nolog,ctl:ruleEngine=Off) right after9800000: skipped byallowwhenSecRuleEngineisOn, and executed whenSecRuleEngineisDetectionOnly(whereallowdoes not fire) so phases 2β5 remain bypassed.tests/unit/modsecurity/test_whitelist_bypass_rule.pycovering both templates,DetectionOnly,USE_WHITELIST=no, andUSE_MODSECURITY_CRS=no.920420viaContent-Type: application/octet-stream) intests/core/modsecurity.ymlfor per-service and global CRS modes.Related issue
Fixes #4248
Affected area
core, plugins
Validation
pytest tests/unit/modsecurity/test_whitelist_bypass_rule.py tests/unit/gen/test_modsec_rule_id_ledger.py -vβ 23 passed (5 template rendering tests + 18 rule-ID ledger tests; template tests run on Windows with in-process POSIX stubs forfcntl/pwd/osandThreadPoolExecutorforTemplator)black --check --line-length 160 tests/unit/modsecurity/test_whitelist_bypass_rule.pyβ passed (1 file would be left unchanged)flake8 --max-line-length=160 --ignore=E266,E402,E501,E722,W503 tests/unit/modsecurity/test_whitelist_bypass_rule.pyβ passedcodespell tests/unit/modsecurity/test_whitelist_bypass_rule.py tests/core/modsecurity.ymlβ passedprettier --check tests/core/modsecurity.ymlβ passed (All matched files use Prettier code style!)tests/core/modsecurity.ymlagainsttests/models/action.py(ActionData)./tests/scripts/test.sh Docker core dev modsecuritywas not run locally (Docker Desktop not running); relies on CI integration matrixDocumentation and changelog
No documentation updates needed β no user-facing settings, defaults, or behaviors changed beyond fixing the documented whitelist bypass for ModSecurity phase 1.