Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
289b6e3
Update libinjection to v4.0.0
Mar 26, 2026
38d9391
Stabilize detectSQLi/XSS regression coverage for full test run
Easton97-Jens Mar 26, 2026
0c610c0
Make benign detectSQLi/XSS regression cases assert no-match logs
Easton97-Jens Mar 26, 2026
0b29169
Merge pull request #23 from Easton97-Jens/codex/migrate-to-libinjecti…
Easton97-Jens Mar 27, 2026
46dabc0
Harden libinjection v4 handling in DetectSQLi/DetectXSS operators
Easton97-Jens Mar 27, 2026
c816add
Fix namespace declaration in libinjection_utils.h
Easton97-Jens Mar 27, 2026
d94cbeb
Fix namespace declaration syntax in libinjection_utils.h
Easton97-Jens Mar 27, 2026
b4b81aa
fix(logging): remove trailing semicolon from debug macros (ms_dbg, ms…
Easton97-Jens Mar 27, 2026
15fd157
Update detect_sqli.cc
Easton97-Jens Mar 27, 2026
4bacc36
Add array header to detect_sqli.cc
Easton97-Jens Mar 27, 2026
f9b2885
Fix formatting issues in transaction.h debug macros
Easton97-Jens Mar 27, 2026
a8debeb
Refactor fingerprint handling in detect_sqli.cc
Easton97-Jens Mar 27, 2026
c67f876
Fix debug logging for XSS detection in detect_xss.cc
Easton97-Jens Mar 27, 2026
7b5bf7f
Fix debug message formatting in detect_sqli.cc
Easton97-Jens Mar 27, 2026
e169d59
Replace push_back with emplace_back for efficiency
Easton97-Jens Mar 27, 2026
724b197
Update operator-detectsqli.json
Easton97-Jens Mar 28, 2026
b9393e7
Update XSS test cases with new payloads
Easton97-Jens Mar 28, 2026
d1eaa04
Update operator-detectsqli.json
Easton97-Jens Mar 28, 2026
7e1d08b
Merge branch 'owasp-modsecurity:v3/master' into v3/master-libinjectio…
Easton97-Jens Mar 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion others/libinjection
Submodule libinjection updated 155 files
79 changes: 52 additions & 27 deletions src/operators/detect_sqli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,70 @@

#include <string>
#include <list>
#include <array>

#include "src/operators/operator.h"
#include "src/operators/libinjection_utils.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.

namespace modsecurity {
namespace operators {

namespace modsecurity::operators {

bool DetectSQLi::evaluate(Transaction *t, RuleWithActions *rule,
const std::string& input, RuleMessage &ruleMessage) {
char fingerprint[8];
int issqli;

issqli = libinjection_sqli(input.c_str(), input.length(), fingerprint);
std::array<char, 8> fingerprint{};

const injection_result_t sqli_result =
libinjection_sqli(input.c_str(), input.length(), fingerprint.data());

if (!t) {
goto tisempty;
if (t == nullptr) {
return isMaliciousLibinjectionResult(sqli_result);
}

if (issqli) {
t->m_matched.push_back(fingerprint);
ms_dbg_a(t, 4, "detected SQLi using libinjection with " \
"fingerprint '" + std::string(fingerprint) + "' at: '" +
input + "'");
if (rule && rule->hasCaptureAction()) {
t->m_collections.m_tx_collection->storeOrUpdateFirst(
"0", std::string(fingerprint));
ms_dbg_a(t, 7, "Added DetectSQLi match TX.0: " + \
std::string(fingerprint));
}
} else {
ms_dbg_a(t, 9, "detected SQLi: not able to find an " \
"inject on '" + input + "'");
switch (sqli_result) {
case LIBINJECTION_RESULT_TRUE:
t->m_matched.emplace_back(fingerprint.data());

ms_dbg_a(t, 4,
std::string("detected SQLi using libinjection with fingerprint '")
+ fingerprint.data() + "' at: '" + input + "'")

if (rule != nullptr && rule->hasCaptureAction()) {
t->m_collections.m_tx_collection->storeOrUpdateFirst(
"0", std::string(fingerprint.data()));

ms_dbg_a(t, 7,
std::string("Added DetectSQLi match TX.0: ")
+ fingerprint.data())
}
break;

case LIBINJECTION_RESULT_ERROR:
ms_dbg_a(t, 4,
std::string("libinjection parser error during SQLi analysis (")
+ libinjectionResultToString(sqli_result)
+ "); treating as match (fail-safe). Input: '"
+ input + "'")

if (rule != nullptr && rule->hasCaptureAction()) {
t->m_collections.m_tx_collection->storeOrUpdateFirst(
"0", input);

ms_dbg_a(t, 7,
std::string("Added DetectSQLi error input TX.0: ")
+ input)
}
break;

case LIBINJECTION_RESULT_FALSE:
ms_dbg_a(t, 9,
std::string("libinjection was not able to find any SQLi in: ")
+ input)
break;
}

tisempty:
return issqli != 0;
return isMaliciousLibinjectionResult(sqli_result);
}


} // namespace operators
} // namespace modsecurity
} // namespace modsecurity::operators
60 changes: 37 additions & 23 deletions src/operators/detect_xss.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,50 @@
#include <string>

#include "src/operators/operator.h"
#include "src/operators/libinjection_utils.h"
#include "libinjection/src/libinjection.h"
#include "libinjection/src/libinjection_error.h"
Comment on lines 22 to +23
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.


namespace modsecurity {
namespace operators {

namespace modsecurity::operators {

bool DetectXSS::evaluate(Transaction *t, RuleWithActions *rule,
const std::string& input, RuleMessage &ruleMessage) {
int is_xss;

is_xss = libinjection_xss(input.c_str(), input.length());

if (t) {
if (is_xss) {
ms_dbg_a(t, 5, "detected XSS using libinjection.");
if (rule && rule->hasCaptureAction()) {
t->m_collections.m_tx_collection->storeOrUpdateFirst(
"0", std::string(input));
ms_dbg_a(t, 7, "Added DetectXSS match TX.0: " + \
std::string(input));

const injection_result_t xss_result =
libinjection_xss(input.c_str(), input.length());

if (t == nullptr) {
return isMaliciousLibinjectionResult(xss_result);
}

switch (xss_result) {
case LIBINJECTION_RESULT_TRUE:
ms_dbg_a(t, 5, std::string("detected XSS using libinjection."))
if (rule != nullptr && rule->hasCaptureAction()) {
t->m_collections.m_tx_collection->storeOrUpdateFirst("0", input);
ms_dbg_a(t, 7, std::string("Added DetectXSS match TX.0: ") + input)
}
} else {
ms_dbg_a(t, 9, "libinjection was not able to " \
"find any XSS in: " + input);
break;

case LIBINJECTION_RESULT_ERROR:
ms_dbg_a(t, 4,
std::string("libinjection parser error during XSS analysis (")
+ libinjectionResultToString(xss_result)
+ "); treating as match (fail-safe). Input: "
+ input)
if (rule != nullptr && rule->hasCaptureAction()) {
t->m_collections.m_tx_collection->storeOrUpdateFirst("0", input);
ms_dbg_a(t, 7, std::string("Added DetectXSS error input TX.0: ") + input)
}
break;

case LIBINJECTION_RESULT_FALSE:
ms_dbg_a(t, 9,
std::string("libinjection was not able to find any XSS in: ") + input)
break;
}
return is_xss != 0;
}

return isMaliciousLibinjectionResult(xss_result);
}

} // namespace operators
} // namespace modsecurity
} // namespace modsecurity::operators
48 changes: 48 additions & 0 deletions src/operators/libinjection_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 - 2021 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/

#ifndef SRC_OPERATORS_LIBINJECTION_UTILS_H_
#define SRC_OPERATORS_LIBINJECTION_UTILS_H_

#include "libinjection/src/libinjection_error.h"

namespace modsecurity::operators {

/*
* libinjection parser errors are handled in fail-safe mode as suspicious
* results, so callers can block on both confirmed detections and parser
* failures.
*/
static inline bool isMaliciousLibinjectionResult(injection_result_t result) {
return result == LIBINJECTION_RESULT_TRUE
|| result == LIBINJECTION_RESULT_ERROR;
}

static inline const char *libinjectionResultToString(injection_result_t result) {
switch (result) {
case LIBINJECTION_RESULT_TRUE:
return "attack-detected";
case LIBINJECTION_RESULT_FALSE:
return "no-attack";
case LIBINJECTION_RESULT_ERROR:
return "parser-error";
}

return "unexpected-result";
}

} // namespace modsecurity::operators

#endif // SRC_OPERATORS_LIBINJECTION_UTILS_H_
Loading
Loading