Skip to content

Allow connectors to avoid unused intervention log payload overhead - #3606

Open
upgle wants to merge 1 commit into
owasp-modsecurity:v3/masterfrom
upgle:feature/intervention-log-opt-out
Open

Allow connectors to avoid unused intervention log payload overhead#3606
upgle wants to merge 1 commit into
owasp-modsecurity:v3/masterfrom
upgle:feature/intervention-log-opt-out

Conversation

@upgle

@upgle upgle commented Aug 1, 2026

Copy link
Copy Markdown

I'm excited to make my first contribution to ModSecurity
thank you for taking the time to review it :)

what

  • add C++ and C APIs to omit unused ModSecurityIntervention::log payload generation
  • keep payload generation enabled by default without changing intervention behavior or other logging channels
  • apply the option to all five existing paths—deny, drop, redirect, and request/response body-limit rejection—with focused tests for each path and both APIs

API

modsecurity.setInterventionLogPayloadEnabled(false);
msc_set_intervention_log_payload_enabled(modsec, 0);

Payload generation remains enabled by default; the C API treats any nonzero value as enabled. The setting is scoped to a ModSecurity instance; configure it before publishing to worker threads. Changing it during active transactions is unsupported.

The implementation reuses a reserved private log-property bit, adding no object field or virtual function. Existing callback setters preserve the bit.

why

The need surfaced while testing ModSecurity in an Envoy integration. The connector consumes intervention status, redirect URLs, and bounded structured rule events, but not the free-form ModSecurityIntervention::log payload; ModSecurity still formats, allocates, copies, and frees it on disruptive requests. This opt-out is intended for high-throughput or latency-sensitive connectors with the same usage pattern while preserving intervention behavior and other logging channels.

An isolated Linux release microbenchmark used 12 alternating-order paired rounds with 50,000 transactions per sample. Enabled and disabled medians were 20.290 and 14.735 microseconds per transaction; the 5.541-microsecond median paired difference represents 27.3% lower phase-1 deny time, with all 12 pairs favoring omission.

Paired phase-1 deny benchmark

Summary by CodeRabbit

  • New Features

    • Added controls to enable or disable human-readable intervention log payloads through both C++ and C APIs.
    • Payload logging is enabled by default and applies to transactions created by the configured instance.
    • Standardized intervention payload handling for deny, drop, redirect, and request/response body-limit actions.
  • Tests

    • Added comprehensive coverage for default behavior, API controls, and preservation of intervention responses.

Allow C and C++ connectors to omit unused intervention log text while preserving disruptive actions and all other logging channels. Keep the default behavior and v3 object layout unchanged, and cover every current payload-producing path with regression tests.
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

The change adds instance-level C++ and C APIs to control intervention log payload generation. Payload creation now uses shared logic across disruptive actions and body-limit rejections. Regression tests cover enabled, disabled, default, and response-preservation behavior.

Intervention log payload control

Layer / File(s) Summary
Payload control APIs and state
headers/modsecurity/modsecurity.h, src/modsecurity.cc, src/intervention_log.h, src/Makefile.am
Adds C++ and C APIs, internal state access, payload helpers, and library source registration.
Intervention payload integration
src/actions/disruptive/*.cc, src/transaction.cc
Uses intervention::setLogPayload for disruptive actions and request or response body-limit rejections.
Regression configuration and coverage
test/common/*, test/regression/*, test/test-cases/regression/intervention-log.json, test/test-suite.in
Adds regression configuration, payload presence tracking, validation, and cases for enabled and disabled payload behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant APIClient
  participant ModSecurity
  participant Transaction
  participant InterventionLog
  APIClient->>ModSecurity: setInterventionLogPayloadEnabled(enabled)
  ModSecurity->>ModSecurity: update internal payload flag
  ModSecurity->>Transaction: apply setting to created transactions
  Transaction->>InterventionLog: setLogPayload(rule message)
  InterventionLog->>Transaction: clear or store intervention payload
Loading

Suggested reviewers: airween

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.88% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: connector APIs can disable unused intervention log payload generation and its overhead.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@sonarqubecloud

sonarqubecloud Bot commented Aug 1, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
test/regression/regression.cc (1)

166-183: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the disable-then-enable pattern.

For enabled != 0, the code disables the payload first, then re-enables it with the actual value. This exercises the real enable transition instead of relying on the already-enabled default, but the reason isn't stated in a comment. A future maintainer could "simplify" this to a single call and silently weaken the regression coverage for the enable path.

Add a short comment explaining why the disable call precedes the enable call.

📝 Proposed clarifying comment
         if (t->intervention_log_payload_api == "c") {
             if (enabled != 0) {
+                // Force a real disabled->enabled transition instead of
+                // relying on the library's already-enabled default, so this
+                // test actually exercises the enable path.
                 modsecurity::msc_set_intervention_log_payload_enabled(
                     &context.m_modsec, 0);
             }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/regression/regression.cc` around lines 166 - 183, Add a concise comment
in the intervention log payload configuration block before the conditional
disable calls, explaining that disabling first forces a genuine enable
transition and preserves regression coverage; keep the existing C API and C++
API call sequence unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@test/regression/regression.cc`:
- Around line 166-183: Add a concise comment in the intervention log payload
configuration block before the conditional disable calls, explaining that
disabling first forces a genuine enable transition and preserves regression
coverage; keep the existing C API and C++ API call sequence unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5059da81-87d1-4402-88c5-9b1e1ca53ca7

📥 Commits

Reviewing files that changed from the base of the PR and between 7ea9fef and 1e16589.

📒 Files selected for processing (15)
  • headers/modsecurity/modsecurity.h
  • src/Makefile.am
  • src/actions/disruptive/deny.cc
  • src/actions/disruptive/drop.cc
  • src/actions/disruptive/redirect.cc
  • src/intervention_log.h
  • src/modsecurity.cc
  • src/transaction.cc
  • test/common/modsecurity_test_context.h
  • test/common/modsecurity_test_results.h
  • test/regression/regression.cc
  • test/regression/regression_test.cc
  • test/regression/regression_test.h
  • test/test-cases/regression/intervention-log.json
  • test/test-suite.in

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