Repository navigation
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Local schema error handling src/operators/validate_schema.cc, src/operators/validate_schema.h |
ValidateSchema::evaluate collects parser errors in a local string and uses it in failure logs. The persistent m_err member was removed. |
Repeated evaluation regression coverage test/test-cases/regression/request-body-parser-xml.json |
The XML request-body test checks error output across repeated bad-schema evaluations and uses the updated validation rule options. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related issues
- owasp-modsecurity/ModSecurity#3678: This PR changes parser-error handling in the
@validateSchemapath; the issue’s proposedREQBODY_ERROR_MSGbehavior remains unimplemented.
Suggested labels: 3.x
Suggested reviewers: zimmerle
Merge Risk: 
Minimal · up to c85e2
-
No actionable merge-blocking risk was identified in the schema error isolation change.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
The title "Do not keep the
@validateSchemaparser errors in the operator" matches the main change. The PR stops ValidateSchema::evaluate() from keeping parser error text in the m_err member. It passes a local string as the libxml2 error context and removes m_err. The title is specific and short, and it names the operator and the behavior that changed.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
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.
|
fzipi
left a comment
There was a problem hiding this comment.
Thanks @tomsommer, this is the right fix: the schema-parse error text is per-evaluation state, so it belongs in a local and not in the shared operator.
What I checked:
- Built master and this branch (libxml2 2.9.13). On master your new
request-body-parser-xml.jsoncase fails: the second evaluation's message carries the first one'sXML Error: ...line. With the change, the file is 6/6. - The libxml2 callbacks run synchronously inside
xmlSchemaParse(), and the parser context is freed on every return path whileschemaErris still in scope, so there is no dangling ctx.evaluate()no longer writes any member, so the cross-transaction race onm_erris gone too. - Ran the full
make checkwith this PR merged together with #3632, #3633 and #3635: no failures.
Comments:
- (non-blocking, pre-existing) Since you are touching that block:
std::stringstream err("XML: Failed to create validation context.");followed byerr << " " << schemaErr;overwrites the start of the message, because the stream does not start in append mode. Building astd::string, or opening the stream withstd::ios_base::out | std::ios_base::ate, would fix it. Fine to leave for a follow-up. - (non-blocking) The only red jobs are the two macOS LMDB ones (
action-expirevar.json,issue-1831.json). Nothing here touches collection/LMDB code, the same job is green on current v3/master, and these runs predate some LMDB fixes there, so a rebase or re-run should clear them.
LGTM.
ValidateSchema::evaluate() installs ValidateSchema::error_load() and ValidateSchema::warn_load() as the libxml2 schema parser callbacks and passes the address of the ValidateSchema member m_err as their user context. Those callbacks append to that string and nothing ever clears it. An operator instance is created while the rules are parsed and lives for as long as the rule set does, which for a web server means the lifetime of the process. Therefore: * every evaluation whose schema parse emits a warning or an error makes m_err grow by the size of the new message, without any bound, and * the message logged for one transaction contains the messages of all the previous transactions that used the same rule, and * concurrent transactions sharing the rule set append to the same std::string at the same time, which is a data race. The accumulated text is per evaluation state, so it is moved to a local std::string in evaluate() and the member is removed from the header. The member was declared inside the WITH_LIBXML2 guard and is only used by the guarded code, so builds configured with --without-libxml are unaffected. The check of the accumulated text in the branch where the parser context itself cannot be created is dropped: at that point no callback has run yet, so the local is always empty. The unbounded part of the growth is cross request and cannot be observed by the single transaction regression harness, but the accumulation is visible within one transaction as soon as the same operator instance is evaluated twice. The regression test added to request-body-parser-xml.json therefore reuses the existing SoapEnvelope-bad.xsd case, which fails to parse, and adds multiMatch so that the operator runs once per transformation. Before this change the debug log of the second evaluation reads XML: Failed to load Schema: test-cases/data/SoapEnvelope-bad.xsd. XML Error: Failed to parse the XML resource '...'. XML Error: Failed to parse the XML resource '...'. with the message repeated once per previous evaluation; after it every evaluation logs the message exactly once. The expected debug_log of the new test asserts that no log line starts with a repeated "XML Error:", so it fails before the change and passes after it.
9e48194 to
a7f1d9d
Compare
std::stringstream err("...") does not open the stream in append mode,
so the following err << " " << schemaErr wrote over the beginning of
"XML: Failed to create validation context." instead of after it. Build
the message with operator<< like the other two error paths do.
xmlSchemaNewValidCtxt() only fails on allocation failure, so there is
no regression test for this path.
|



what
ValidateSchema::evaluate()passes a localstd::stringas the libxml2 schema-parser error/warning context instead of the operator memberm_err; the member is removed.request-body-parser-xml.json: the existing bad-schema case withmultiMatch, so the same operator instance is evaluated twice in one transaction; it asserts the error text is not repeated. It fails before the change and passes after it.why
error_load()/warn_load()append into their context and nothing ever clearedm_err. An operator instance lives as long as the rule set, i.e. the process lifetime in nginx, and the schema is re-parsed on every evaluation. So every evaluation whose schema parse emits a warning or error grew the string without bound, the logged message for one transaction contained the messages of all previous ones, and concurrent transactions appended to the same string, which is a data race.WITH_LIBXML2guard and had no other reader;--without-libxmlcompilation of the translation unit was verified.Evidence (unfixed tree, new test): the second evaluation logs
with the message repeated once per previous evaluation. After the fix each evaluation logs it once. This is growth of a live string, so valgrind reports no lost blocks; the test is the evidence.
make checkon this branch: TOTAL 5044, PASS 5028, SKIP 16, FAIL 0.references
Summary by CodeRabbit