Repository navigation
v2: Separate request-body bucket handling from the reader - #3716
vortexopenclaw wants to merge 2 commits into
Conversation
Separate bucket reads, nonempty chunk storage and whole-body limit handling. Collapse repeated limit diagnostics while preserving the distinct no-files limit policy, stream compile-time paths, byte accounting, EOS state and completion status mapping. Add 24 native chunked boundary tests across both engines and limit actions, validated against the pre-refactor implementation. This addresses the SonarCloud cognitive-complexity finding without suppressing it.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
| Layer / File(s) | Summary |
|---|---|
Limit and storage policy handling apache2/apache2_io.c |
Helpers check whole-body limits and handle storage outcomes according to the engine mode and body-limit action. |
Bucket reading and regression coverage apache2/apache2_io.c, tests/regression/config/10-request-buckets.t |
The bucket loop delegates reading, accounting, and EOS handling to a helper. Regression tests check expected response codes and phase-2 logging across the configured cases. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Refactor
Suggested reviewers: airween
Merge Risk: 
Minimal · previous review c4da9
-
No concrete issue remains that would prevent merging after normal checks.
Pre-merge checks: 
2 · 
2
-
Failed checks: 2 warnings Passed checks: 2 passed-
Full details: Title check
-
Explanation
The title "v2: Separate request-body bucket handling from the reader" matches the main change. The PR extracts request-body bucket reading, chunk storage, and whole-body limit handling out of read_request_body() in apache2/apache2_io.c, and the file summary confirms new helpers for these tasks. The title's "v2:" prefix is a version tag and adds no meaning, but the rest of the title is specific and accurate.
-
Full details: Linked Issues check
-
Explanation
Issue
#2807requires premature EOF in a JSON request to fail withREQBODY_ERRORinstead of producing HTTP 500. The whole-PR diff changes onlyapache2/apache2_io.cbucket handling and adds bucket-limit tests intests/regression/config/10-request-buckets.t. It contains no JSON status mapping or premature-EOF regression test. The PR description also states that it does not resolve#2807.Resolution
Implement the
#2807JSON premature-EOF behavior and add an automated regression test that verifies the requiredREQBODY_ERRORand HTTP status. Otherwise, remove#2807as a direct link and link the issue that owns the bucket-handling refactor.
Full details: Out of Scope Changes check
-
Explanation
The linked issue concerns JSON premature EOF and its HTTP status. The added helpers and 24 tests concern chunked request-body limits, no-files limits, limit actions, and bucket accounting. The diff provides no concrete connection between these changes and the
#2807behavior. The current PR description confirms that the changes are independent of the JSON fix.Resolution
Split the bucket refactor and bucket-limit tests into a PR with an appropriate linked issue, or make this PR implement
#2807and retain only changes that support that objective.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Comment @coderabbitai help to get the list of available commands.
|
@coderabbitai review |
✅ Action performed
|
|
|
Thanks @vortexopenclaw for splitting this out of #3629! I walked through the extracted helpers against the original loop, and they are equivalent: the whole-body limit decisions, the However, I have to put this PR on hold for now, sorry. As I explained in #3629, there is an older open PR by @hnakamur, #3483 (with its v3 counterpart #3476), which rewrites exactly this part of
The current 413 under Since #3483 has been waiting longer and keeps v2 and v3 consistent, I'd like to review and merge it first. After that, it would be great if you could rebase this refactor on top of it, so the helpers follow the new structure and the bucket tests assert the fixed behaviour. A refactor is much easier to adapt to a functional change than the other way around, so I think this order is the fairer one. When you rebase, please also:
Thanks for your patience, and for the boundary tests: they will be very useful for verifying #3483 as well. |



Summary
Make ModSecurity v2's request-body handling easier to review and safer to maintain, without changing which requests it accepts or rejects.
When Apache receives a request body in chunks, ModSecurity must enforce size limits, store the data, and decide whether to reject the request or continue processing it. Today, those decisions are mixed together in a long reader function with repeated checks. That makes security-sensitive changes harder to review and increases the risk of accidentally changing how a configured limit is enforced.
This PR separates those responsibilities into small, focused helpers and adds 24 regression tests for requests just below, exactly at, and just above the configured limits. The benefit is clearer control flow and explicit test coverage of the existing policies—not a new blocking policy or a change to HTTP responses.
What this improves:
Scope and implementation
Split out of #3629 at the maintainer's request: #3629 (review). This PR targets
v2/masterindependently of the JSON fix and changes only:apache2/apache2_io.c: extractcheck_request_body_limit,store_request_body_chunk, andread_request_body_bucketfromread_request_body().tests/regression/config/10-request-buckets.t: add the 24 request-limit boundary cases described above.There is no JSON return-code change or HTTP 400 mapping here. Completion failures retain the base's behavior. This PR does not resolve #2807 or choose between the overlapping status changes in #3629 and #3515.
Intended invariants
Preserve bucket-read failure handling, limit checks before storage, stream accounting, request-body length accounting, ProcessPartial stopping, storage-error policy, and end-of-stream flags/order. Preserve the existing distinction between whole-body and no-files limits rather than harmonizing their policies in a refactor.
The extraction removes duplicated whole-body error-message construction while retaining the same message and return decisions. It is submitted separately so maintainers can assess whether a maintenance-branch refactor is appropriate; the small JSON fix should not need to absorb this churn just to satisfy a complexity gate.
Verification
Fresh source export of this branch with the pinned libinjection submodule, Ubuntu 24.04 arm64, Apache 2.4.58 and YAJL. Container networking disabled; no published ports.
--enable-pcre-study=yes --enable-pcre-jit CFLAGS=-Werror=format-security.make test: 4,250/4,250 unit tests pass.The actual HTTP runner was
USER=root LOGNAME=root perl run-regression-tests.pl -S . -p 8090 -vfromtests/; use the actual test-process user forUSER/LOGNAME.These results cover the standard build, not certification of every optional build or every malformed transport path. Cross-platform CI and maintainer review are still required. No production deployment is included.