Skip to content

fix: silence libxml2 parser errors on every libxml2 version - #3677

Open
fzipi wants to merge 1 commit into
owasp-modsecurity:v3/masterfrom
fzipi:v3/issue-3563-libxml2-stderr
Open

fzipi wants to merge 1 commit into
owasp-modsecurity:v3/masterfrom
fzipi:v3/issue-3563-libxml2-stderr

Conversation

@fzipi

@fzipi fzipi commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

what

Replace the direct ctxt->options |= XML_PARSE_NOWARNING | XML_PARSE_NOERROR assignments in the XML body processor with xmlCtxtUseOptions().

why

Since 3.0.15, a malformed XML request body makes libxml2 print its own error (body.xml:1: parser error : Extra content at the end of the document plus the context lines) to stderr. With the nginx connector that lands in error.log without the usual timestamp prefix (#3563).

  • 624a0de removed the deprecated xmlSetGenericErrorFunc() call with a null handler, which is what kept 3.0.14 quiet.
  • b9dc9cc tried to compensate by OR-ing the NOERROR/NOWARNING flags straight into ctxt->options.
  • libxml2 only honours flags stored that way from 2.13 on. Older releases (2.9 through 2.12: Amazon Linux 2023, Ubuntu 22.04, RHEL 9, Debian 12) apply them inside xmlCtxtUseOptions() by clearing the SAX error callbacks, so the direct assignment is a no-op there. That is why the reporters on Amazon Linux see the lines and the maintainers on newer distros could not reproduce.

xmlCtxtUseOptions() works on both old and new libxml2 and is not deprecated.

Verified with a small push-parser program against libxml2 2.9.13 and 2.15.4:

libxml2 no flags options |= (current) xmlCtxtUseOptions()
2.9.13 prints error prints error silent
2.15.4 prints error silent silent

and with the existing variable-REQBODY_PROCESSOR_ERROR.json regression test on a build linked against 2.9.13: one parser error line on stderr before, none after. The regression harness cannot assert on stderr, so there is no new automated test.

references

Fixes #3563. Related: #3455 (624a0de, b9dc9cc).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Updated XML parsing configuration. There are no user-visible changes; parsing behavior and the handling of parser warnings and errors remain unchanged. No new features or bug fixes are included in this update.

Since 3.0.15 (b9dc9cc) the XML body processor sets XML_PARSE_NOERROR and
XML_PARSE_NOWARNING by OR-ing them into ctxt->options directly. libxml2
only honours options stored that way from 2.13 on; older releases (2.9
through 2.12, e.g. Amazon Linux 2023, Ubuntu 22.04, RHEL 9) apply the
flags inside xmlCtxtUseOptions() by clearing the SAX error callbacks, so
the direct assignment is a no-op and every malformed body prints
"body.xml:1: parser error : ..." to stderr, which nginx forwards to its
error log without a timestamp prefix. 3.0.14 did not show this because
it still called xmlSetGenericErrorFunc() with a null handler, which
624a0de removed as deprecated.

Call xmlCtxtUseOptions() instead, which works on both old and new
libxml2 and is not deprecated. Verified with a push-parser test program
against libxml2 2.9.13 and 2.15.4, and with the existing
variable-REQBODY_PROCESSOR_ERROR regression test, whose stderr output
goes from one parser error line to none.

Fixes owasp-modsecurity#3563

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 80168517-6830-46bb-8eb9-03d6459fd07f
📥 Commits

Reviewing files that changed from the base of the PR and between 48e561b and c3c7ba8.

📒 Files selected for processing (1)
  • src/request_body_processor/xml.cc

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

📝 Walkthrough

Both XML parser contexts now set warning and error suppression flags through xmlCtxtUseOptions instead of modifying the context’s options field directly.

Changes: XML parser option configuration

Layer / File(s) Summary
Apply options to both parser contexts
src/request_body_processor/xml.cc
The document parser and ARGS SAX parser now apply the warning and error suppression flags through xmlCtxtUseOptions.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Suggested reviewers: airween

Merge Risk: ⚪ Minimal · up to c3c7b

The change applies XML diagnostic-suppression settings through libxml2’s API. No concrete regression in the supported repository workflow is established, so no actionable merge blocker remains.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Issue #3563 reports unwanted libxml2 parser-error output for malformed XML request bodies. In src/request_body_processor/xml.cc, both push-parser contexts now call xmlCtxtUseOptions() with `XML_PA…
Out of Scope Changes check Passed The reviewed change is limited to XML body-parser option configuration in src/request_body_processor/xml.cc. Both modified calls support the #3563 objective. The summary reports no public API change…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: silencing libxml2 parser errors across supported libxml2 versions.
  • Fix all pre-merge checks with AI
✨ 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

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

@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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

REQBODY_ERROR "Extra content at the end of the document" after 3.0.15 update

1 participant