Skip to content

Update SQLi/XSS operators for libinjection v4.0.0#3522

Open
Easton97-Jens wants to merge 18 commits intoowasp-modsecurity:v3/masterfrom
Easton97-Jens:v3/master-libinjection-v4.0
Open

Update SQLi/XSS operators for libinjection v4.0.0#3522
Easton97-Jens wants to merge 18 commits intoowasp-modsecurity:v3/masterfrom
Easton97-Jens:v3/master-libinjection-v4.0

Conversation

@Easton97-Jens
Copy link
Copy Markdown
Contributor

what

  • Updated the SQLi and XSS detection operators to support the newer libinjection return codes (injection_result_t).
  • Added explicit handling for TRUE, FALSE, and ERROR results from libinjection_sqli and libinjection_xss.
  • Treated LIBINJECTION_RESULT_ERROR as a fail-safe match to avoid missing potentially malicious input.
  • Preserved diagnostic context by storing raw input in TX.0 when capture is enabled, even on parser errors.
  • Maintained previous behavior for positive detections (fingerprints for SQLi, input storage for XSS).
  • Added regression tests for benign inputs to ensure no false positives are introduced.

why

  • Newer versions of libinjection introduced injection_result_t, requiring explicit handling in ModSecurity operators.
  • Without this update, parser errors could be handled inconsistently and weaken fail-safe detection behavior.
  • Treating parser errors as matches ensures conservative and security-focused handling when input cannot be reliably parsed.
  • Preserving captured input during error cases improves debugging and visibility for rule authors.
  • Regression tests ensure the updated logic does not introduce false positives for safe inputs.

references

  • Related to adapting ModSecurity to newer libinjection APIs.
  • Adds regression coverage for parser error handling and safe input validation.

@Easton97-Jens Easton97-Jens changed the title V3/master libinjection v4.0 Update SQLi/XSS operators for libinjection v4.0.0 Mar 27, 2026
@airween
Copy link
Copy Markdown
Member

airween commented Mar 27, 2026

Hi @Easton97-Jens,

thanks for this PR - could you take a look at the failed tests on macOS and also the SonarCloud reports?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates ModSecurity’s @detectSQLi and @detectXSS operators to work with libinjection v4’s injection_result_t return codes, including explicit handling for TRUE/FALSE/ERROR and fail-safe matching on parser errors.

Changes:

  • Switched SQLi/XSS operator evaluation to injection_result_t and added explicit TRUE/FALSE/ERROR handling.
  • Implemented fail-safe behavior by treating LIBINJECTION_RESULT_ERROR as a match and preserving captured input when capture is enabled.
  • Added regression coverage for benign inputs for both operators.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

File Description
src/operators/detect_xss.cc Update XSS operator to handle libinjection v4 result codes and fail-safe error behavior.
src/operators/detect_sqli.cc Update SQLi operator to handle libinjection v4 result codes and fail-safe error behavior.
test/test-cases/regression/operator-detectxss.json Add benign-input regression case for @detectXSS.
test/test-cases/regression/operator-detectsqli.json Add benign-input regression case for @detectSQLi.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +47 to +57
case LIBINJECTION_RESULT_ERROR:
is_match = true;
ms_dbg_a(t, 4, "libinjection parser error during XSS "
"analysis; treating as match (fail-safe). Input: " + input);
if (rule && rule->hasCaptureAction()) {
t->m_collections.m_tx_collection->storeOrUpdateFirst(
"0", std::string(input));
ms_dbg_a(t, 7, "Added DetectXSS error input TX.0: " + \
std::string(input));
}
break;
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

The new LIBINJECTION_RESULT_ERROR fail-safe path changes behavior (treat error as match and optionally capture raw input). Please add a regression test that reliably triggers a libinjection ERROR result and asserts the match/capture behavior, so this security-critical branch stays covered.

Copilot uses AI. Check for mistakes.
"Host": "localhost",
"User-Agent": "curl/7.38.0",
"Accept": "*/*",
"Content-Length": "18",
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

Content-Length doesn't match the request body length here (param1=just_a_value is 19 bytes). The regression harness may auto-correct it, but keeping it accurate avoids confusion when reusing this case outside the harness.

Suggested change
"Content-Length": "18",
"Content-Length": "19",

Copilot uses AI. Check for mistakes.

#include "src/operators/operator.h"
#include "libinjection/src/libinjection.h"
#include "libinjection/src/libinjection_error.h"
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

New dependency on libinjection/src/libinjection_error.h: please ensure this header is present in the vendored libinjection submodule version and is included in release artifacts (e.g., add it to others/Makefile.am noinst_HEADERS if make dist/packaging relies on that list). Otherwise builds from distribution tarballs can fail with a missing-header error.

Suggested change
#include "libinjection/src/libinjection_error.h"

Copilot uses AI. Check for mistakes.
Comment on lines 21 to +22
#include "libinjection/src/libinjection.h"
#include "libinjection/src/libinjection_error.h"
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

New dependency on libinjection/src/libinjection_error.h: please ensure this header is present in the vendored libinjection submodule version and is included in release artifacts (e.g., add it to others/Makefile.am noinst_HEADERS if make dist/packaging relies on that list). Otherwise builds from distribution tarballs can fail with a missing-header error.

Copilot uses AI. Check for mistakes.
Comment on lines +55 to +65
case LIBINJECTION_RESULT_ERROR:
is_match = true;
ms_dbg_a(t, 4, "libinjection parser error during SQLi "
"analysis; treating as match (fail-safe). Input: '" + input + "'");
if (rule && rule->hasCaptureAction()) {
t->m_collections.m_tx_collection->storeOrUpdateFirst(
"0", std::string(input));
ms_dbg_a(t, 7, "Added DetectSQLi error input TX.0: " + \
std::string(input));
}
break;
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

The new LIBINJECTION_RESULT_ERROR fail-safe path changes behavior (treat error as match and optionally capture raw input). Please add a regression test that reliably triggers a libinjection ERROR result and asserts the match/capture behavior, so this security-critical branch stays covered.

Copilot uses AI. Check for mistakes.
@Easton97-Jens
Copy link
Copy Markdown
Contributor Author

Hi,

thanks for pointing that out!

I had a look at the failed macOS tests and the SonarCloud report. The Lua-related error does not seem to be caused by the changes in this PR, but rather appears to be a general issue in the project. Therefore, I’d suggest addressing it separately from this PR.

Let me know if you’d still like me to investigate it further here.

Best regards

@fzipi
Copy link
Copy Markdown
Collaborator

fzipi commented Mar 28, 2026

The macos build should be fixed by #3524. Once it is merged, you can rebase.

@sonarqubecloud
Copy link
Copy Markdown

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.

4 participants