Skip to content

iis: fail closed (HTTP 500) on ModSecurity config load failure - #3617

Open
A13501350 wants to merge 1 commit into
owasp-modsecurity:v2/masterfrom
A13501350:iis-fix-config-fail-closed
Open

iis: fail closed (HTTP 500) on ModSecurity config load failure#3617
A13501350 wants to merge 1 commit into
owasp-modsecurity:v2/masterfrom
A13501350:iis-fix-config-fail-closed

Conversation

@A13501350

Copy link
Copy Markdown

Summary

In iis/mymodule.cpp, CMyHttpModule::OnBeginRequest currently handles a failure to retrieve or parse the ModSecurity configuration by setting hr = S_OK and falling through to RQ_NOTIFICATION_CONTINUE. That means a request for which the WAF configuration could not be loaded is passed through without any inspection -- i.e. the WAF silently fails open.

On a malformed or missing modsecurity.conf (or a config that fails to parse), this leaves the site completely unprotected, with no signal to the client.

Change

  • When the config cannot be retrieved or parsed, return HTTP 500 (WAF internal error. ...) and SetRequestHandled() instead of continuing.
  • Track configFailTime / configLoadingFailed on the stored context so a transient failure does not spam the event log every request: within a 10s window the cached failure is reported immediately; after that the w3wp worker is recycled so it re-reads the config.
  • Added #include <time.h> (the file now uses time() / difftime()).

Why fail closed

For a security control, failing open on a bad config is the more dangerous default. Returning 500 makes the failure visible and avoids silently unprotected traffic. (If a deployment truly needs fail-open behaviour this can be discussed, but the safe default is fail closed.)

Provenance

Adapted from microsoft/ModSecurity branch waf_iis (config-load-failure handling). Verified still missing on current v2/master tip (0875b19, v2.9.14).

Previously, when the ModSecurity configuration could not be retrieved or
parsed, OnBeginRequest set hr=S_OK and fell through to RQ_NOTIFICATION_CONTINUE,
so requests silently bypassed the WAF (fail-open). On a malformed or missing
config this leaves the site unprotected.

Now explicitly return HTTP 500 with a clear error when the config cannot be
loaded. A short retry window (10s) is cached so a transient failure does not
hammer the event log, and a persistent failure recycles the w3wp worker.

Adapted from microsoft/ModSecurity waf_iis.
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 91d09cba-6413-46b5-bdf5-ac6004c8b9a5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant