Skip to content

Fix checked parsing for argument and JSON depth limits - #3602

Open
AnnoyingTechnology wants to merge 3 commits into
owasp-modsecurity:v3/masterfrom
AnnoyingTechnology:contribute-back/checked-limit-parser
Open

AnnoyingTechnology wants to merge 3 commits into
owasp-modsecurity:v3/masterfrom
AnnoyingTechnology:contribute-back/checked-limit-parser

Conversation

@AnnoyingTechnology

@AnnoyingTechnology AnnoyingTechnology commented Jul 23, 2026 •

Copy link
Copy Markdown

I have excess 5.6-sol and Fable 5 credits, and decided to use them to contribute back to OSS that I depend upon.

gpt5.6-sol cross-checked by Opus 4.8. Fable 5 could not cross-check due to safeties being triggered.

what

  • Parse SecArgumentsLimit through its existing checked
    ConfigUnsignedInt wrapper.
  • Do the same for SecRequestBodyJsonDepthLimit.
  • Return directive-specific configuration errors for values outside the
    wrapper's range.
  • Add regressions for the uint32_t maximum, 2^32, and decimals wider than
    uint64_t.
  • Register the new regression fixture in the standard make check suite.

why

PR #3421 converted these fields to checked unsigned wrappers so out-of-range
configuration would fail during startup, but these two grammar productions
still assigned atoi(...) directly.

On the tested platform, 4294967296 wrapped to zero. A zero
SecArgumentsLimit skipped every request argument, while a zero
SecRequestBodyJsonDepthLimit prevented the top-level JSON argument from being
exposed. The new code uses the same checked parsing pattern as the adjacent
body, PCRE, and upload limits.

This is configuration validation for trusted directives, not a remotely
triggerable vulnerability claim.

validation

  • New regression: 6 passed, 0 failed.
  • Existing SecArgumentsLimit regression: 2 passed, 0 failed.
  • Existing JSON parser regression: 6 passed, 0 failed.
  • Full make check: 5,049 total; 4,997 passed; 52 skipped; 0 failed.
  • git diff --check: pass.
  • Test JSON parsed with jq: pass.

Base: v3/master at
7ea9fefbe0ba409d8733b4d682c8c4c059cd028d.

references

Summary by CodeRabbit

  • Bug Fixes

    • Configuration limits now receive consistent validation, with clear errors for values that exceed supported ranges.
    • Correctly handles valid maximum values for argument and JSON-depth limits.
  • Tests

    • Added regression coverage for valid limits and out-of-range values across supported directives.

@sonarqubecloud

Copy link
Copy Markdown

@airween airween added the 3.x Related to ModSecurity version 3.x label Jul 28, 2026

@fzipi fzipi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @AnnoyingTechnology, this is a nice catch and a clean fix.

What I checked:

  • Reproduced the bug on current v3/master: with SecArgumentsLimit 4294967296 the value wraps to 0, the debug log shows Skipping request argument, over limit (0), and a simple ARGS:a deny rule no longer fires. modsec-rules-check accepts that config without complaint.
  • With your change the same config fails to load with Failed to parse SecArgumentsLimit: Value is too big., and the uint64-overflow case gives Number out of range. The new productions follow the same pattern as the neighbouring SecRequestBodyLimit one.
  • Regenerated the parser with bison 3.8.2: the committed seclang-parser.cc is byte-identical to fresh output.
  • The new regression file is registered in test-suite.in. 4 of its 6 cases fail on master and all 6 pass with the fix. Full make check on the PR merged into current v3/master: 5141 total, 5121 pass, 20 skip, 0 fail.

Comments:

  1. (blocking for merge, mechanical only) The branch is behind v3/master and src/parser/seclang-parser.cc now conflicts. The .yy and test-suite.in merge cleanly, so a rebase plus regenerating the parser with bison 3.8.2 (--enable-parser-generation, or run bison on the .yy) is all that's needed. I did that locally and it builds and passes.

  2. (non-blocking) The two "accepts the uint32 maximum" cases only check that the config loads, and they also pass on master because atoi happens to give 4294967295 there. If you want them to show more, you could send an argument and assert it's still inspected (e.g. a deny rule on ARGS with SecArgumentsLimit 4294967295). Fine to leave as is.

Approving on the code; it just needs that rebase before it can be merged.

AnnoyingTechnology and others added 3 commits November 26, 2026 12:12
The uint32 maximum cases only checked that the configuration loaded,
which also passed with the previous atoi() parsing. Send an argument
and a JSON body and assert that a deny rule on them still fires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AnnoyingTechnology
AnnoyingTechnology force-pushed the contribute-back/checked-limit-parser branch from 8d3612c to f3cfe39 Compare November 27, 2026 07:37
@AnnoyingTechnology

Copy link
Copy Markdown
Author

Thanks for the thorough review. Rebased on current v3/master and regenerated src/parser/seclang-parser.cc with bison 3.8.2. Also took your second suggestion: the uint32-maximum cases now send an argument and a JSON body and assert a deny rule still fires (verified they fail with the limit forced to 0). Full make check: 5154 total, 5093 pass, 61 skip, 0 fail.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The parser now validates SecArgumentsLimit and SecRequestBodyJsonDepthLimit through their property parsers. New regression cases cover maximum uint32 values and out-of-range inputs.

Changes: Unsigned limit parsing

Layer / File(s) Summary
Validate unsigned limit directives
src/parser/seclang-parser.yy, src/parser/seclang-parser.cc
The two directives now use their limit objects’ parse methods. Parse failures report directive-specific details and invoke YYERROR. The generated parser and source mappings are updated.
Test limit boundaries
test/test-cases/regression/config-unsigned-int-limits.json, test/test-suite.in
Six regression cases cover uint32 maximum values, values above that limit, and values wider than uint64. The test-suite input includes the new regression configuration.

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

Change: Bug fix

Suggested reviewers: airween, fzipi

Merge Risk: Minimal · up to f3cfe

This change makes SecArgumentsLimit and SecRequestBodyJsonDepthLimit reject out-of-range values with directive-specific configuration errors instead of silently truncating them. Regression tests cover the boundary values. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: checked parsing for the argument and JSON depth limit directives. The raw summary and PR objectives confirm that SecArgumentsLimit and SecRequestBodyJsonDepthLimit now…
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.
Full details: Title check

Explanation

The title names the main change: checked parsing for the argument and JSON depth limit directives. The raw summary and PR objectives confirm that SecArgumentsLimit and SecRequestBodyJsonDepthLimit now use the checked ConfigUnsignedInt wrapper instead of atoi, with directive-specific errors for out-of-range values. The title is short and specific, though it does not mention the new regression tests.

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3b14da7f-c9da-426a-b390-c3ca85448c1d
Commits

Reviewing files that changed from the base of the PR and between 475aece and f3cfe39.

Files selected for processing: 4

  • src/parser/seclang-parser.cc
  • src/parser/seclang-parser.yy
  • test/test-cases/regression/config-unsigned-int-limits.json
  • test/test-suite.in

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

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

Labels

3.x Related to ModSecurity version 3.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants