Skip to content

Add CMake to CI, guard libxml2 APIs and harden XML parsing (fix leak)#80

Open
Easton97-Jens wants to merge 8 commits intov3/master-json2from
codex/fix-visible-errors-and-regressions
Open

Add CMake to CI, guard libxml2 APIs and harden XML parsing (fix leak)#80
Easton97-Jens wants to merge 8 commits intov3/master-json2from
codex/fix-visible-errors-and-regressions

Conversation

@Easton97-Jens
Copy link
Copy Markdown
Owner

Motivation

  • Fix failing vendored libxml2 configure in Linux CI when cmake is not installed.
  • Remove risky literal-based network detection in XML resource loader that triggered Sonar Security Hotspot while keeping network resources blocked.
  • Eliminate a potential memory leak reported for VariableValue allocation and restore Windows/libxml2 cross-version compatibility for XML hardening changes.

Description

  • CI: install cmake in Linux dependency steps and make build/libxml.m4 detect cmake via AC_PATH_PROG, emitting a clear error if missing, so vendored libxml2 remains the desired path.
  • Refactor src/request_body_processor/xml.cc to use a neutral scheme parser isRemoteResource (parses URI scheme and matches http/https/ftp/ftps/sftp) instead of direct "http://"/"https://" literals, removing the Sonar hotspot while retaining blocking semantics.
  • Add libxml2 version feature-guards (#if LIBXML_VERSION >= 21400) around newer APIs (xmlCtxtSetOptions/xmlCtxtSetResourceLoader/xmlSchemaSetResourceLoader and related resource-loader code) and provide fallbacks for older versions (use xmlCtxtUseOptions and a scoped external-entity loader fallback) so Windows/older-libxml2 builds remain protected.
  • Centralize security policy initialization (initializeSecurityPolicy) to ensure XML_PARSE_NONET is always set and XML_PARSE_NO_XXE is used when available, otherwise the scoped fallback denies external resources without weakening protection.
  • Fix potential leak in src/variables/xml.cc by using std::unique_ptr<VariableValue> and calling release() only when the value is actually pushed into the output vector, making ownership explicit and analyzer-friendly.

Testing

  • Ran ./build.sh (autotools prep) and it completed successfully in this environment.
  • Ran ./configure --enable-assertions=yes which failed due to a missing git submodule (libInjection) unrelated to these changes; this is expected in the current container and not caused by the PR.
  • Verified libxml2 presence/version with pkg-config --modversion libxml-2.0 which returned 2.9.14, confirming code compiles against an older libxml2 for fallback paths.
  • Performed syntax-only checks: g++ -std=c++17 -DWITH_LIBXML2 -I. -I./headers $(pkg-config --cflags libxml-2.0) -fsyntax-only src/request_body_processor/xml.cc and ... src/variables/xml.cc and both passed.
  • Ran git diff --check and there were no whitespace/patch errors.

Notes: full make/make check and Windows-native builds could not be completed inside this container due to missing git submodules and lack of a Windows toolchain; these remain recommended CI validations and the PR preserves the security guarantees across libxml2 versions with documented fallbacks.


Codex Task

Easton97-Jens and others added 8 commits April 14, 2026 20:35
…g-offener-sonar-probleme-7954xf

Modernize codebase: nullptr/default initializers, std::string_view, smart pointers and minor cleanups
…nar-befunde-in-pr-#3540

Address open CRITICAL Sonar nesting and cognitive-complexity findings
…ocessing-improvements

Refactor XML processing, add secure libxml2 handling and vendored build support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant